1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Test performance of a task "spawn ladder", in which children task have
12 // many ancestor taskgroups, but with only a few such groups alive at a time.
13 // Each child task has to enlist as a descendant in each of its ancestor
14 // groups, but that shouldn't have to happen for already-dead groups.
16 // The filename is a song reference; google it in quotes.
18 // ignore-pretty very bad with line comments
20 use std::sync::mpsc::{channel, Sender};
22 use std::str::from_str;
24 use std::thread::Thread;
27 fn child_generation(gens_left: uint, tx: Sender<()>) {
28 // This used to be O(n^2) in the number of generations that ever existed.
29 // With this code, only as many generations are alive at a time as tasks
31 Thread::spawn(move|| {
32 if gens_left & 1 == 1 {
33 task::deschedule(); // shake things up a bit
36 child_generation(gens_left - 1, tx); // recurse
44 let args = os::args();
45 let args = if os::getenv("RUST_BENCH").is_some() {
46 vec!("".to_string(), "100000".to_string())
47 } else if args.len() <= 1 {
48 vec!("".to_string(), "100".to_string())
50 args.clone().into_iter().collect()
53 let (tx, rx) = channel();
54 child_generation(from_str::<uint>(args[1].as_slice()).unwrap(), tx);
55 if rx.recv().is_err() {
56 panic!("it happened when we slumbered");