rust/src/test/bench/task-perf-spawnalot.rs

25 lines
421 B
Rust
Raw Normal View History

use std;
import vec;
import task;
import uint;
import str;
2011-10-20 20:34:04 -07:00
fn f(&&n: uint) {
let i = 0u;
while i < n {
2012-01-06 20:55:56 -08:00
task::join(task::spawn_joinable {|| g(); });
2011-09-02 15:34:58 -07:00
i += 1u;
}
}
2012-01-06 22:02:05 -08:00
fn g() { }
2011-09-02 15:34:58 -07:00
fn main(args: [str]) {
let n =
if vec::len(args) < 2u {
10u
} else { uint::parse_buf(str::bytes(args[1]), 10u) };
let i = 0u;
2012-01-06 20:55:56 -08:00
while i < n { task::spawn {|| f(n); }; i += 1u; }
}