From 492dba8bfe8b5d906bce6eb0e90e095c168863ec Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 14 Jan 2012 19:00:59 -0800 Subject: [PATCH] bench: Update shootout-fibo for performance --- src/test/bench/shootout-fibo.rs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/test/bench/shootout-fibo.rs b/src/test/bench/shootout-fibo.rs index afb1b4a9289..e6e42e36704 100644 --- a/src/test/bench/shootout-fibo.rs +++ b/src/test/bench/shootout-fibo.rs @@ -1,19 +1,20 @@ +use std; - -// -*- rust -*- fn fib(n: int) -> int { - - - // Several of the posted 'benchmark' versions of this compute the - // wrong Fibonacci numbers, of course. - if n == 0 { - ret 0; - } else { if n <= 2 { ret 1; } else { ret fib(n - 1) + fib(n - 2); } } + if n < 2 { + ret 1; + } else { + ret fib(n - 1) + fib(n - 2); + } } -fn main() { - assert (fib(8) == 21); - assert (fib(15) == 610); - log(debug, fib(8)); - log(debug, fib(15)); +fn main(args: [str]) { + // FIXME: #1527 + sys::set_min_stack(1000000u); + let n = if vec::len(args) == 2u { + int::from_str(args[1]) + } else { + 40 + }; + std::io::println(#fmt("%d\n", fib(n))); }