rust/src/test/bench/task-perf-alloc-unwind.rs

88 lines
2.0 KiB
Rust
Raw Normal View History

2012-06-02 19:42:48 -05:00
// xfail-win32
use std;
2012-09-05 14:32:05 -05:00
use std::list::{List, Cons, Nil};
use std::time::precise_time_s;
2012-06-02 19:42:48 -05:00
fn main() {
let (repeat, depth) = if os::getenv(~"RUST_BENCH").is_some() {
2012-06-02 19:42:48 -05:00
(50, 1000)
} else {
(10, 10)
};
run(repeat, depth);
}
fn run(repeat: int, depth: int) {
for iter::repeat(repeat as uint) {
2012-08-22 19:24:52 -05:00
debug!("starting %.4f", precise_time_s());
do task::try {
2012-08-20 14:23:37 -05:00
recurse_or_fail(depth, None)
2012-06-02 19:42:48 -05:00
};
2012-08-22 19:24:52 -05:00
debug!("stopping %.4f", precise_time_s());
2012-06-02 19:42:48 -05:00
}
}
2012-09-04 16:12:14 -05:00
type nillist = List<()>;
2012-06-02 19:42:48 -05:00
// Filled with things that have to be unwound
enum st {
st_({
box: @nillist,
unique: ~nillist,
fn_box: fn@() -> @nillist,
fn_unique: fn~() -> ~nillist,
tuple: (@nillist, ~nillist),
vec: ~[@nillist],
2012-06-02 19:42:48 -05:00
res: r
})
}
2012-08-15 20:46:55 -05:00
struct r {
let _l: @nillist;
new(l: @nillist) { self._l = l; }
drop {}
2012-06-02 19:42:48 -05:00
}
2012-08-20 14:23:37 -05:00
fn recurse_or_fail(depth: int, st: Option<st>) {
2012-06-02 19:42:48 -05:00
if depth == 0 {
2012-08-22 19:24:52 -05:00
debug!("unwinding %.4f", precise_time_s());
2012-06-02 19:42:48 -05:00
fail;
} else {
let depth = depth - 1;
2012-08-06 14:34:08 -05:00
let st = match st {
2012-08-20 14:23:37 -05:00
None => {
2012-06-02 19:42:48 -05:00
st_({
2012-09-04 16:12:14 -05:00
box: @Nil,
unique: ~Nil,
fn_box: fn@() -> @nillist { @Nil::<()> },
fn_unique: fn~() -> ~nillist { ~Nil::<()> },
tuple: (@Nil, ~Nil),
vec: ~[@Nil],
res: r(@Nil)
2012-06-02 19:42:48 -05:00
})
}
2012-08-20 14:23:37 -05:00
Some(st) => {
2012-06-02 19:42:48 -05:00
let fn_box = st.fn_box;
let fn_unique = st.fn_unique;
st_({
2012-09-04 16:12:14 -05:00
box: @Cons((), st.box),
unique: ~Cons((), @*st.unique),
fn_box: fn@() -> @nillist { @Cons((), fn_box()) },
fn_unique: fn~() -> ~nillist { ~Cons((), @*fn_unique()) },
tuple: (@Cons((), st.tuple.first()),
~Cons((), @*st.tuple.second())),
vec: st.vec + ~[@Cons((), st.vec.last())],
res: r(@Cons((), st.res._l))
2012-06-02 19:42:48 -05:00
})
}
};
2012-08-20 14:23:37 -05:00
recurse_or_fail(depth, Some(st));
2012-06-02 19:42:48 -05:00
}
}