In Rust
use std::time::Instant;
fn fibonacci( n : i32 ) -> i32 {
if n < 0 {
0
}
else if n == 0 {
0
}
else if n == 1 {
1
}
else {
fibonacci(n - 1 ) + fibonacci(n -2)
}
}
fn main() {
let start = Instant::now();
println!("fib(35) = {}", fibonacci(35) );
let elapsed = start.elapsed();
println!("Millis: {} ms", elapsed.as_millis());
}
First I compile it (cargo build)
Then I run it with
perl -MTime::HiRes=time -e 'printf "%.9f\n", time' ; /Users/npalardy/RustProjects/fibonacci/target/debug/fibonacci ; perl -MTime::HiRes=time -e 'printf "%.9f\n", time'
1590771171.419712067
fib(35) = 9227465
Millis: 115 ms
1590771171.550776005
or .492 seconds total - only 115 msec to do fib(35) though
and this time includes start up and tear down by the OS to start the process
compiled a comparable xojo app aggressively and ran it the same way (just the perl portion)
1590771626.041557074
9227465
1590771626.853302002
so .811 sec which isnt shabby