-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Description
When I looked at the benchmarks, I was particularly surprised because I couldn't imagine the recursive fib being that fast compared to C.
The R recursion example is not an apples-to-apples comparison, because it is using two accumulators. In fact the commented out R code at https://github.com/JulesKouatchou/basic_language_comparison/blob/master/R/test_fibonacci.R#L15 is the right one. Or alternatively, all languages should use the one with two accumulators.
For example, here's the Julia version that does what the R version does and runs as fast.
function Fib(N)
function F(N, a, b)
N == 0 && return b
F(N-1, a+b, a)
end
F(N, 1, 0)
end
Much of this was done by @syxpek on the Julia slack. I am just reporting it.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels