3 // Broken due to arena API problems.
5 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
6 // file at the top-level directory of this distribution and at
7 // http://rust-lang.org/COPYRIGHT.
9 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
10 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
11 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
12 // option. This file may not be copied, modified, or distributed
13 // except according to those terms.
20 node(&'self tree<'self>, &'self tree<'self>, int),
23 fn item_check(t: &tree) -> int {
26 node(left, right, item) => {
27 return item + item_check(left) - item_check(right);
32 fn bottom_up_tree<'r>(arena: &'r mut arena::Arena, item: int, depth: int)
36 || node(bottom_up_tree(arena, 2 * item - 1, depth - 1),
37 bottom_up_tree(arena, 2 * item, depth - 1),
40 return arena.alloc(|| nil);
44 let args = os::args();
45 let args = if os::getenv(~"RUST_BENCH").is_some() {
47 } else if args.len() <= 1u {
53 let n = int::from_str(args[1]).get();
56 if min_depth + 2 > n {
57 max_depth = min_depth + 2;
62 let mut stretch_arena = arena::Arena();
63 let stretch_depth = max_depth + 1;
64 let stretch_tree = bottom_up_tree(&mut stretch_arena, 0, stretch_depth);
66 io::println(fmt!("stretch tree of depth %d\t check: %d",
68 item_check(stretch_tree)));
70 let mut long_lived_arena = arena::Arena();
71 let long_lived_tree = bottom_up_tree(&mut long_lived_arena, 0, max_depth);
72 let mut depth = min_depth;
73 while depth <= max_depth {
74 let iterations = int::pow(2, (max_depth - depth + min_depth) as uint);
77 while i <= iterations {
78 let mut temp_tree = bottom_up_tree(&mut long_lived_arena, i, depth);
79 chk += item_check(temp_tree);
80 temp_tree = bottom_up_tree(&mut long_lived_arena, -i, depth);
81 chk += item_check(temp_tree);
84 io::println(fmt!("%d\t trees of depth %d\t check: %d",
85 iterations * 2, depth,
89 io::println(fmt!("long lived trees of depth %d\t check: %d",
91 item_check(long_lived_tree)));