rust/src/test/bench/task-perf-jargon-metal-smoke.rs

57 lines
1.8 KiB
Rust
Raw Normal View History

// xfail-pretty
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// 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.
// Test performance of a task "spawn ladder", in which children task have many
// 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.
use std::comm;
use std::os;
use std::task;
use std::uint;
fn child_generation(gens_left: uint, c: comm::Chan<()>) {
// 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() {
if gens_left & 1 == 1 {
task::deschedule(); // shake things up a bit
}
if gens_left > 0 {
2013-02-15 04:44:18 -06:00
child_generation(gens_left - 1, c); // recurse
} else {
c.send(())
}
2014-01-27 17:29:50 -06:00
});
}
fn main() {
let args = os::args();
let args = if os::getenv("RUST_BENCH").is_some() {
~[~"", ~"100000"]
2012-09-19 00:44:34 -05:00
} else if args.len() <= 1 {
~[~"", ~"100"]
} else {
2013-07-02 14:47:32 -05:00
args.clone()
};
2013-12-15 20:17:43 -06:00
let (p,c) = Chan::new();
child_generation(from_str::<uint>(args[1]).unwrap(), c);
2013-12-15 20:17:43 -06:00
if p.recv_opt().is_none() {
fail!("it happened when we slumbered");
}
}