Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I was just reviewing the Mathematica benchmark code linked from the Julia language home page http://julialang.org/. The stated goal of the benchmarks is to test the performance of specific algorithms, expressed in a reasonable idiom in each language, and all languages use the same algorithm.

In particular, the Fibonacci benchmarks are all recursive, and the Mathematica code reads

fib = Compile[{{n, _Integer}}, 
    If[n < 2, n, fib[n - 1] + fib[n - 2]],
    CompilationTarget -> "WVM"

Now, dynamic programming is certainly a reasonable idiom in Mathematica:

fib[n_Integer]:= fib[n]= If[n < 2, n, fib[n - 1] + fib[n - 2]]

and this dynamic uncompiled code will be much faster than the benchmark code, especially for large n (unless the WVM compiler is smart enough to do automatic memoization).

The test only computes fib[20] and it would be most interesting to try say fib[100] in the various languages (the times for R, MATLAB, and OCTAVE are excessive even for n=20).

It would also be useful, I think, for better coding of all the benchmark examples, if someone has the time and energy ...

share|improve this question
You know that self-answering is not at all frowned upon? ;-) –  Yves Klett Jun 9 at 7:46
For the Fibonacci example, this might be related: mathematica.stackexchange.com/questions/31593/… –  blochwave Jun 9 at 8:19
What exactly is the question? This is a Q&A site after all... –  Ajasja Jun 9 at 12:53
One could interpret this as a question along the lines "Do people have input on better Mathematica coding of examples in ...?" –  Daniel Lichtblau Jun 9 at 15:45
It looks like everything is using Compile. I wouldn't write code like this for the benchmark. Even if in some cases the compiled code is faster, it is not natural for Mathematica. I'd only use Compile in cases when it's clearly the best approach, e.g. the mandelbrot test. I did write a set of Mathematica benchmarks when Julia was first made public, but I got lazy at the quicksort and stopped there. I hacve the rest, should dig them up. –  Szabolcs Jun 9 at 17:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.