rust/src/test/bench/task-perf-jargon-metal-smoke.rs
Björn Steinbrink bdc182cc41 Use static string with fail!() and remove fail!(fmt!())
fail!() used to require owned strings but can handle static strings
now. Also, it can pass its arguments to fmt!() on its own, no need for
the caller to call fmt!() itself.
2013-05-14 16:36:23 +02:00

56 lines
1.8 KiB
Rust

// 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.
//
// The filename is a song reference; google it in quotes.
use core::cell::Cell;
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
// alive at a time,
let c = Cell(c);
do task::spawn_supervised {
let c = c.take();
if gens_left & 1 == 1 {
task::yield(); // shake things up a bit
}
if gens_left > 0 {
child_generation(gens_left - 1, c); // recurse
} else {
c.send(())
}
}
}
fn main() {
let args = os::args();
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"100000"]
} else if args.len() <= 1 {
~[~"", ~"100"]
} else {
copy args
};
let (p,c) = comm::stream();
child_generation(uint::from_str(args[1]).get(), c);
if p.try_recv().is_none() {
fail!("it happened when we slumbered");
}
}