Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 78 lines (69 sloc) 2.295 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
edc317b @brson Remove arg vectors from main functions. Stop supporting them.
brson authored
28 fn main() {
29 let args = os::args();
92743dc @msullivan Move the world over to using the new style string literals and types.…
msullivan authored
30 let args = if os::getenv(~"RUST_BENCH").is_some() {
31 ~[~"", ~"17"]
4fec4cd @brson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
32 } else if args.len() <= 1u {
92743dc @msullivan Move the world over to using the new style string literals and types.…
msullivan authored
33 ~[~"", ~"8"]
9c21673 @brson bench: Update shootout-binarytrees for style
brson authored
34 } else {
4fec4cd @brson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
35 args
9c21673 @brson bench: Update shootout-binarytrees for style
brson authored
36 };
4fec4cd @brson bench: Add hard mode to benchmarks. Activate with RUST_BENCH.
brson authored
37
38 let n = int::from_str(args[1]).get();
df7f21d @marijnh Reformat for new syntax
marijnh authored
39 let min_depth = 4;
dc07280 @nikomatsakis make --enforce-mut-vars always on, add mut annotations to remaining f…
nikomatsakis authored
40 let mut max_depth;
df7f21d @marijnh Reformat for new syntax
marijnh authored
41 if min_depth + 2 > n {
ce72993 @graydon Reformat source tree (minus a couple tests that are still grumpy).
graydon authored
42 max_depth = min_depth + 2;
8774493 @pcwalton test: Rewrite binarytrees to use arenas
pcwalton authored
43 } else {
44 max_depth = n;
45 }
46
a605fd0 @bstrie CamelCasify lots of std
bstrie authored
47 let stretch_arena = arena::Arena();
df7f21d @marijnh Reformat for new syntax
marijnh authored
48 let stretch_depth = max_depth + 1;
8774493 @pcwalton test: Rewrite binarytrees to use arenas
pcwalton authored
49 let stretch_tree = bottom_up_tree(&stretch_arena, 0, stretch_depth);
50
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
51 io::println(fmt!("stretch tree of depth %d\t check: %d",
9c21673 @brson bench: Update shootout-binarytrees for style
brson authored
52 stretch_depth,
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
53 item_check(stretch_tree)));
8774493 @pcwalton test: Rewrite binarytrees to use arenas
pcwalton authored
54
a605fd0 @bstrie CamelCasify lots of std
bstrie authored
55 let long_lived_arena = arena::Arena();
8774493 @pcwalton test: Rewrite binarytrees to use arenas
pcwalton authored
56 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
57 let mut depth = min_depth;
df7f21d @marijnh Reformat for new syntax
marijnh authored
58 while depth <= max_depth {
50fb4c3 @marijnh Increase precedence of as operator
marijnh authored
59 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
60 let mut chk = 0;
61 let mut i = 1;
df7f21d @marijnh Reformat for new syntax
marijnh authored
62 while i <= iterations {
8774493 @pcwalton test: Rewrite binarytrees to use arenas
pcwalton authored
63 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
64 chk += item_check(temp_tree);
8774493 @pcwalton test: Rewrite binarytrees to use arenas
pcwalton authored
65 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
66 chk += item_check(temp_tree);
67 i += 1;
68 }
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
69 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
70 iterations * 2, depth,
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
71 chk));
ce72993 @graydon Reformat source tree (minus a couple tests that are still grumpy).
graydon authored
72 depth += 2;
467b9f3 @brson Implement the rest of the binary trees shootout benchmark
brson authored
73 }
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
74 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
75 max_depth,
29f32b4 @paulstansifer `m1!{...}` -> `m1!(...)`
paulstansifer authored
76 item_check(long_lived_tree)));
518dc52 @brson Reformat
brson authored
77 }
Something went wrong with that request. Please try again.