I came across this question on Stackoverflow and was curious where Rust is in these benchmarks performance - Ackermann very inefficient with Haskell/GHC - Stack Overflow
The Rust version is as below:
fn ack(m: usize, n: usize) -> usize {
if m == 0 { n+1 }
else if n == 0 { ack (m-1, 1) }
else { ack(m-1, ack(m, n-1)) }
}
fn main() {
println!("{}", ack(4,1));
}
On my computer, the C programs runs in 2.3s with gcc -O2
, 1.9s with gcc -O3
, and 3.1s with rustc -O
. I use gcc 6.2.0
and rust 1.13.0
.
What is it that makes this compiled Rust program slightly slower than C?