Skip to content

Commit

Permalink
bench: Update shootout-ackermann for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Jan 15, 2012
1 parent 492dba8 commit c53d0a0
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/test/bench/shootout-ackermann.rs
@@ -1,25 +1,24 @@
use std;




// -*- rust -*-
fn ack(m: int, n: int) -> int { fn ack(m: int, n: int) -> int {
if m == 0 { if m == 0 {
ret n + 1; ret n + 1
} else { } else {
if n == 0 { if n == 0 {
ret ack(m - 1, 1); 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() { fn main(args: [str]) {
assert (ack(0, 0) == 1); // FIXME: #1527
assert (ack(3, 2) == 29); sys::set_min_stack(1000000u);
assert (ack(3, 4) == 125); let n = if vec::len(args) == 2u {
// This takes a while; but a comparison may amuse: on win32 at least, the int::from_str(args[1])
// posted C version of the 'benchmark' running ack(4,1) overruns its stack } else {
// segment and crashes. We just grow our stack (to 4mb) as we go. 11

};
// assert (ack(4,1) == 65533); std::io::println(#fmt("Ack(3,%d): %d\n", n, ack(3, n)));

} }

0 comments on commit c53d0a0

Please sign in to comment.