Permalink
Browse files

bench: Update shootout-ackermann for performance

  • Loading branch information...
1 parent 492dba8 commit c53d0a0af80c963c05f848a470f672509df03026 @brson brson committed Jan 15, 2012
Showing with 14 additions and 15 deletions.
  1. +14 −15 src/test/bench/shootout-ackermann.rs
@@ -1,25 +1,24 @@
+use std;
-
-
-// -*- rust -*-
fn ack(m: int, n: int) -> int {
if m == 0 {
- ret n + 1;
+ ret n + 1
} else {
if n == 0 {
ret ack(m - 1, 1);
- } else { ret ack(m - 1, ack(m, n - 1)); }
+ } else {
+ ret ack(m - 1, ack(m, n - 1));
+ }
}
}
-fn main() {
- assert (ack(0, 0) == 1);
- assert (ack(3, 2) == 29);
- assert (ack(3, 4) == 125);
- // This takes a while; but a comparison may amuse: on win32 at least, the
- // posted C version of the 'benchmark' running ack(4,1) overruns its stack
- // segment and crashes. We just grow our stack (to 4mb) as we go.
-
- // assert (ack(4,1) == 65533);
-
+fn main(args: [str]) {
+ // FIXME: #1527
+ sys::set_min_stack(1000000u);
+ let n = if vec::len(args) == 2u {
+ int::from_str(args[1])
+ } else {
+ 11
+ };
+ std::io::println(#fmt("Ack(3,%d): %d\n", n, ack(3, n)));
}

0 comments on commit c53d0a0

Please sign in to comment.