bench: Update shootout-fibo for performance
This commit is contained in:
parent
bc77d7bdb0
commit
492dba8bfe
@ -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)));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user