Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 77 lines (68 sloc) 2.283 kB
ea01ee2 @brson Convert 'use' to 'extern mod'. Remove old 'use' syntax
brson authored
1 extern mod std;
f686896 @pcwalton test: "import" -> "use"
pcwalton authored
2 use std::arena;
3 use methods = std::arena::Arena;
467b9f3 @brson Implement the rest of the binary trees shootout benchmark
brson authored
4
3d6c791 @nikomatsakis update syntax to include a slash
nikomatsakis authored
5 enum tree/& { nil, node(&tree, &tree, int), }
d6b7c96 @graydon Populate tree.
graydon authored
6
8774493 @pcwalton test: Rewrite binarytrees to use arenas
pcwalton authored
7 fn item_check(t: &tree) -> int {
ecaf9e3 @brson Convert alt to match. Stop parsing alt
brson authored
8 match *t {
025d866 @brson Switch alts to use arrows
brson authored
9 nil => { return 0; }
10 node(left, right, item) => {
b355936 @brson Convert ret to return
brson authored
11 return item + item_check(left) - item_check(right);
df7f21d @marijnh Reformat for new syntax
marijnh authored
12 }
d6b7c96 @graydon Populate tree.
graydon authored
13 }
14 }
15
a605fd0 @bstrie CamelCasify lots of std
bstrie authored
16 fn bottom_up_tree(arena: &r/arena::Arena,
652b312 @nikomatsakis more sound treatment of fn& regions; change all & to be distinct
nikomatsakis authored
17 item: int,
18 depth: int) -> &r/tree {
df7f21d @marijnh Reformat for new syntax
marijnh authored
19 if depth > 0 {
31c5cec @nikomatsakis Purge placement new; Make borrowck know about unary move.
nikomatsakis authored
20 return arena.alloc(
21 || node(bottom_up_tree(arena, 2 * item - 1, depth - 1),
22 bottom_up_tree(arena, 2 * item, depth - 1),
23 item));
8774493 @pcwalton test: Rewrite binarytrees to use arenas
pcwalton authored
24 }
31c5cec @nikomatsakis Purge placement new; Make borrowck know about unary move.
nikomatsakis authored
25 return arena.alloc(|| nil);
467b9f3 @brson Implement the rest of the binary trees shootout benchmark
brson authored
26 }
27
267ab11 @nikomatsakis use + mode for (almost) everything when not using legacy modes
nikomatsakis authored
28 fn main(++args: ~[~str]) {
92743dc @msullivan Move the world over to using the new style string literals and types.…
msullivan authored
29 let args = if os::getenv(~"RUST_BENCH").is_some() {
30 ~[~"", ~"17"]
4fec4cd @brson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
31 } else if args.len() <= 1u {
92743dc @msullivan Move the world over to using the new style string literals and types.…
msullivan authored
32 ~[~"", ~"8"]
9c21673 @brson bench: Update shootout-binarytrees for style
brson authored
33 } else {
4fec4cd @brson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
34 args
9c21673 @brson bench: Update shootout-binarytrees for style
brson authored
35 };
4fec4cd @brson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
36
37 let n = int::from_str(args[1]).get();
df7f21d @marijnh Reformat for new syntax
marijnh authored
38 let min_depth = 4;
dc07280 @nikomatsakis make --enforce-mut-vars always on, add mut annotations to remaining f…
nikomatsakis authored
39 let mut max_depth;
df7f21d @marijnh Reformat for new syntax
marijnh authored
40 if min_depth + 2 > n {
ce72993 @graydon Reformat source tree (minus a couple tests that are still grumpy).
graydon authored
41 max_depth = min_depth + 2;
8774493 @pcwalton test: Rewrite binarytrees to use arenas
pcwalton authored
42 } else {
43 max_depth = n;
44 }
45
a605fd0 @bstrie CamelCasify lots of std
bstrie authored
46 let stretch_arena = arena::Arena();
df7f21d @marijnh Reformat for new syntax
marijnh authored
47 let stretch_depth = max_depth + 1;
8774493 @pcwalton test: Rewrite binarytrees to use arenas
pcwalton authored
48 let stretch_tree = bottom_up_tree(&stretch_arena, 0, stretch_depth);
49
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
50 io::println(fmt!("stretch tree of depth %d\t check: %d",
9c21673 @brson bench: Update shootout-binarytrees for style
brson authored
51 stretch_depth,
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
52 item_check(stretch_tree)));
8774493 @pcwalton test: Rewrite binarytrees to use arenas
pcwalton authored
53
a605fd0 @bstrie CamelCasify lots of std
bstrie authored
54 let long_lived_arena = arena::Arena();
8774493 @pcwalton test: Rewrite binarytrees to use arenas
pcwalton authored
55 let long_lived_tree = bottom_up_tree(&long_lived_arena, 0, max_depth);
dc07280 @nikomatsakis make --enforce-mut-vars always on, add mut annotations to remaining f…
nikomatsakis authored
56 let mut depth = min_depth;
df7f21d @marijnh Reformat for new syntax
marijnh authored
57 while depth <= max_depth {
50fb4c3 @marijnh Increase precedence of as operator
marijnh authored
58 let iterations = int::pow(2, (max_depth - depth + min_depth) as uint);
dc07280 @nikomatsakis make --enforce-mut-vars always on, add mut annotations to remaining f…
nikomatsakis authored
59 let mut chk = 0;
60 let mut i = 1;
df7f21d @marijnh Reformat for new syntax
marijnh authored
61 while i <= iterations {
8774493 @pcwalton test: Rewrite binarytrees to use arenas
pcwalton authored
62 let mut temp_tree = bottom_up_tree(&long_lived_arena, i, depth);
ce72993 @graydon Reformat source tree (minus a couple tests that are still grumpy).
graydon authored
63 chk += item_check(temp_tree);
8774493 @pcwalton test: Rewrite binarytrees to use arenas
pcwalton authored
64 temp_tree = bottom_up_tree(&long_lived_arena, -i, depth);
ce72993 @graydon Reformat source tree (minus a couple tests that are still grumpy).
graydon authored
65 chk += item_check(temp_tree);
66 i += 1;
67 }
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
68 io::println(fmt!("%d\t trees of depth %d\t check: %d",
6f5853f @graydon Libc/os/run/rand/io reorganization. Close #1373. Close #1638.
graydon authored
69 iterations * 2, depth,
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
70 chk));
ce72993 @graydon Reformat source tree (minus a couple tests that are still grumpy).
graydon authored
71 depth += 2;
467b9f3 @brson Implement the rest of the binary trees shootout benchmark
brson authored
72 }
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
73 io::println(fmt!("long lived trees of depth %d\t check: %d",
6f5853f @graydon Libc/os/run/rand/io reorganization. Close #1373. Close #1638.
graydon authored
74 max_depth,
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
75 item_check(long_lived_tree)));
518dc52 @brson Reformat
brson authored
76 }
Something went wrong with that request. Please try again.