4 ms·
> It is important to note that the benchmark codes are not written for absolute maximal performance (the fastest code to compute recursion_fibonacci(20) is the
by xiaodai 9y ago
> It is important to note that the benchmark codes are not written for absolute maximal performance (the fastest code to compute recursion_fibonacci(20) is the constant literal 6765). Instead, the benchmarks are written to test the performance of identical algorithms and code patterns implemented in each language.
This is quite interesting. So potentially the code for other languages are not the best. It would complete the argument then that the "code patterns" is more often than not the most "natural" e.g. it translates well from pseudo-code.
When I was trying Julia I keep trying to vectorize code like I do in R and it took me a while to get comfortable with writing loops again. Vectorized code in R can be quite fast, but there is big caveat - you need a lot more memory to do the same task (until ALTEREP makes into R Base) . E.g. say I wanted to find the maximum of `abs(a^2)` in R where `a` is a vector, so I would do `max(abs(a^2)` this creates a temporary vector. In Julia I can do `maximum(x->abs(x^2), a)` and achieve similar (if not better performance) using much less RAM. This is qutie important if you deal with large datasets (e.g. Fannie Mae data at 1.8 billion rows).
- ChrisRackauckas 9y agoThe code here isn't the best in any language. A purely recursive Fibonacci is a terribly inefficient way to do the calculation because it will recompute every `fib(n-1)` a few times, making the complexity exponential. But that's what makes it great benchmark of recursion. People then try replacing the code with an O(n) vectorized version and say "hey, we beat Julia!" but that completely misses the point that (1) yes, you can do the O(n) version in Julia too and it will be faster but also (2) this is a test of recursion with the name "recursion" in the name.
- goerz 9y agoI'd say the way to go is to take the same algorithm (pseudocode), and then implement that idiomatically in all given languages