]> git.lizzy.rs Git - rust.git/blob - src/test/bench/task-perf-jargon-metal-smoke.rs
auto merge of #13600 : brandonw/rust/master, r=brson
[rust.git] / src / test / bench / task-perf-jargon-metal-smoke.rs
1 // ignore-pretty
2
3 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
4 // file at the top-level directory of this distribution and at
5 // http://rust-lang.org/COPYRIGHT.
6 //
7 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10 // option. This file may not be copied, modified, or distributed
11 // except according to those terms.
12
13 // Test performance of a task "spawn ladder", in which children task have
14 // many ancestor taskgroups, but with only a few such groups alive at a time.
15 // Each child task has to enlist as a descendant in each of its ancestor
16 // groups, but that shouldn't have to happen for already-dead groups.
17 //
18 // The filename is a song reference; google it in quotes.
19
20 use std::comm;
21 use std::os;
22 use std::task;
23 use std::uint;
24
25 fn child_generation(gens_left: uint, tx: comm::Sender<()>) {
26     // This used to be O(n^2) in the number of generations that ever existed.
27     // With this code, only as many generations are alive at a time as tasks
28     // alive at a time,
29     spawn(proc() {
30         if gens_left & 1 == 1 {
31             task::deschedule(); // shake things up a bit
32         }
33         if gens_left > 0 {
34             child_generation(gens_left - 1, tx); // recurse
35         } else {
36             tx.send(())
37         }
38     });
39 }
40
41 fn main() {
42     let args = os::args();
43     let args = if os::getenv("RUST_BENCH").is_some() {
44         vec!(~"", ~"100000")
45     } else if args.len() <= 1 {
46         vec!(~"", ~"100")
47     } else {
48         args.clone().move_iter().collect()
49     };
50
51     let (tx, rx) = channel();
52     child_generation(from_str::<uint>(*args.get(1)).unwrap(), tx);
53     if rx.recv_opt().is_err() {
54         fail!("it happened when we slumbered");
55     }
56 }