Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 86 lines (73 sloc) 2.067 kB
027e97b @brson bench: Add an unwinding benchmark
brson authored
1 // xfail-win32
2
3 use std;
4
5 import tuple::{first, second};
6 import std::list::{list, cons, nil};
7 import std::time::precise_time_s;
8
9 fn main() {
10 let (repeat, depth) = if os::getenv("RUST_BENCH").is_some() {
11 (50, 1000)
12 } else {
13 (10, 10)
14 };
15
16 run(repeat, depth);
17 }
18
19 fn run(repeat: int, depth: int) {
20 iter::repeat(repeat as uint) { ||
21 #debug("starting %.4f", precise_time_s());
22 task::try { ||
23 recurse_or_fail(depth, none)
24 };
25 #debug("stopping %.4f", precise_time_s());
26 }
27 }
28
29 type nillist = list<()>;
30
31 // Filled with things that have to be unwound
32 enum st {
33 st_({
34 box: @nillist,
35 unique: ~nillist,
36 fn_box: fn@() -> @nillist,
37 fn_unique: fn~() -> ~nillist,
38 tuple: (@nillist, ~nillist),
39 vec: [@nillist],
40 res: r
41 })
42 }
43
44 resource r(_l: @nillist) {
45 }
46
47 fn recurse_or_fail(depth: int, st: option<st>) {
48 if depth == 0 {
49 #debug("unwinding %.4f", precise_time_s());
50 fail;
51 } else {
52 let depth = depth - 1;
53
54 let st = alt st {
55 none {
56 st_({
57 box: @nil,
58 unique: ~nil,
59 fn_box: fn@() -> @nillist { @nil::<()> },
60 fn_unique: fn~() -> ~nillist { ~nil::<()> },
61 tuple: (@nil, ~nil),
62 vec: [@nil],
63 res: r(@nil)
64 })
65 }
66 some(st) {
67 let fn_box = st.fn_box;
68 let fn_unique = st.fn_unique;
69
70 st_({
71 box: @cons((), st.box),
72 unique: ~cons((), @*st.unique),
73 fn_box: fn@() -> @nillist { @cons((), fn_box()) },
74 fn_unique: fn~() -> ~nillist { ~cons((), @*fn_unique()) },
75 tuple: (@cons((), first(st.tuple)),
76 ~cons((), @*second(st.tuple))),
77 vec: st.vec + [@cons((), st.vec.last())],
78 res: r(@cons((), *(st.res)))
79 })
80 }
81 };
82
83 recurse_or_fail(depth, some(st));
84 }
85 }
Something went wrong with that request. Please try again.