Skip to content

Commit 492dba8

Browse files
committed
bench: Update shootout-fibo for performance
1 parent bc77d7b commit 492dba8

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/test/bench/shootout-fibo.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
use std;
12

2-
3-
// -*- rust -*-
43
fn fib(n: int) -> int {
5-
6-
7-
// Several of the posted 'benchmark' versions of this compute the
8-
// wrong Fibonacci numbers, of course.
9-
if n == 0 {
10-
ret 0;
11-
} else { if n <= 2 { ret 1; } else { ret fib(n - 1) + fib(n - 2); } }
4+
if n < 2 {
5+
ret 1;
6+
} else {
7+
ret fib(n - 1) + fib(n - 2);
8+
}
129
}
1310

14-
fn main() {
15-
assert (fib(8) == 21);
16-
assert (fib(15) == 610);
17-
log(debug, fib(8));
18-
log(debug, fib(15));
11+
fn main(args: [str]) {
12+
// FIXME: #1527
13+
sys::set_min_stack(1000000u);
14+
let n = if vec::len(args) == 2u {
15+
int::from_str(args[1])
16+
} else {
17+
40
18+
};
19+
std::io::println(#fmt("%d\n", fib(n)));
1920
}

0 commit comments

Comments
 (0)