2014-02-07 13:08:32 -06:00
|
|
|
// ignore-pretty
|
2013-02-24 12:57:16 -06:00
|
|
|
|
2014-02-07 13:08:32 -06:00
|
|
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
2012-12-10 19:32:48 -06:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-03-06 01:35:12 -06:00
|
|
|
// Test performance of a task "spawn ladder", in which children task have
|
2012-08-01 23:07:12 -05:00
|
|
|
// many ancestor taskgroups, but with only a few such groups alive at a time.
|
|
|
|
// Each child task has to enlist as a descendant in each of its ancestor
|
|
|
|
// groups, but that shouldn't have to happen for already-dead groups.
|
|
|
|
//
|
2012-08-03 18:26:25 -05:00
|
|
|
// The filename is a song reference; google it in quotes.
|
2012-08-01 23:07:12 -05:00
|
|
|
|
2013-05-24 21:35:29 -05:00
|
|
|
use std::comm;
|
|
|
|
use std::os;
|
|
|
|
use std::task;
|
|
|
|
use std::uint;
|
2013-02-25 16:04:32 -06:00
|
|
|
|
2014-03-09 16:58:32 -05:00
|
|
|
fn child_generation(gens_left: uint, tx: comm::Sender<()>) {
|
2012-08-01 23:07:12 -05:00
|
|
|
// This used to be O(n^2) in the number of generations that ever existed.
|
|
|
|
// With this code, only as many generations are alive at a time as tasks
|
2012-08-03 18:26:25 -05:00
|
|
|
// alive at a time,
|
2014-01-27 17:29:50 -06:00
|
|
|
spawn(proc() {
|
2012-08-01 23:07:12 -05:00
|
|
|
if gens_left & 1 == 1 {
|
2013-08-16 14:49:40 -05:00
|
|
|
task::deschedule(); // shake things up a bit
|
2012-08-01 23:07:12 -05:00
|
|
|
}
|
|
|
|
if gens_left > 0 {
|
2014-03-09 16:58:32 -05:00
|
|
|
child_generation(gens_left - 1, tx); // recurse
|
2012-08-06 16:15:44 -05:00
|
|
|
} else {
|
2014-03-09 16:58:32 -05:00
|
|
|
tx.send(())
|
2012-08-01 23:07:12 -05:00
|
|
|
}
|
2014-01-27 17:29:50 -06:00
|
|
|
});
|
2012-08-01 23:07:12 -05:00
|
|
|
}
|
|
|
|
|
2012-10-03 21:16:27 -05:00
|
|
|
fn main() {
|
|
|
|
let args = os::args();
|
2013-07-17 14:31:20 -05:00
|
|
|
let args = if os::getenv("RUST_BENCH").is_some() {
|
2014-03-05 16:02:44 -06:00
|
|
|
vec!(~"", ~"100000")
|
2012-09-19 00:44:34 -05:00
|
|
|
} else if args.len() <= 1 {
|
2014-03-05 16:02:44 -06:00
|
|
|
vec!(~"", ~"100")
|
2012-08-01 23:07:12 -05:00
|
|
|
} else {
|
2014-03-05 17:28:08 -06:00
|
|
|
args.clone().move_iter().collect()
|
2012-08-01 23:07:12 -05:00
|
|
|
};
|
|
|
|
|
2014-03-09 16:58:32 -05:00
|
|
|
let (tx, rx) = channel();
|
2014-03-05 17:28:08 -06:00
|
|
|
child_generation(from_str::<uint>(*args.get(1)).unwrap(), tx);
|
2014-03-09 16:58:32 -05:00
|
|
|
if rx.recv_opt().is_none() {
|
2013-10-21 15:08:31 -05:00
|
|
|
fail!("it happened when we slumbered");
|
2012-08-06 16:15:44 -05:00
|
|
|
}
|
2012-08-01 23:07:12 -05:00
|
|
|
}
|