Skip to main content
edited tags
Link
Karsten7
  • 27.7k
  • 5
  • 76
  • 138
Tweeted twitter.com/#!/StackMma/status/493739576943710208
Source Link
TheDoctor
  • 2.9k
  • 1
  • 17
  • 17

Relative performance of the Julia language

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

ClearAll[fib]; 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 ...