Skip to content

Commit 8d7dfa4

Browse files
committed
Linked failure: Add '100 generations' bench test (#1868)
1 parent 7d9c61a commit 8d7dfa4

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Test performance of a task "spawn ladder", in which children task have many
2+
// many ancestor taskgroups, but with only a few such groups alive at a time.
3+
// Each child task has to enlist as a descendant in each of its ancestor
4+
// groups, but that shouldn't have to happen for already-dead groups.
5+
//
6+
// The filename is a reference; google it in quotes.
7+
8+
fn child_generation(gens_left: uint) {
9+
// This used to be O(n^2) in the number of generations that ever existed.
10+
// With this code, only as many generations are alive at a time as tasks
11+
// alive at a time,
12+
do task::spawn_supervised {
13+
if gens_left & 1 == 1 {
14+
task::yield(); // shake things up a bit
15+
}
16+
if gens_left > 0 {
17+
child_generation(gens_left - 1); // recurse
18+
}
19+
}
20+
}
21+
22+
fn main(args: ~[~str]) {
23+
let args = if os::getenv(~"RUST_BENCH").is_some() {
24+
~[~"", ~"100000"]
25+
} else if args.len() <= 1u {
26+
~[~"", ~"100"]
27+
} else {
28+
copy args
29+
};
30+
31+
child_generation(uint::from_str(args[1]).get());
32+
}

0 commit comments

Comments
 (0)