title: Julia (Julia-lang) Performance Compared to Fortran and Python
body: <p>I adapted a simple program to compute and plot the movement vortices of to Julia to test the language, I also wrote it in Python for no particular reason.</p>
  
  <p><strong>(Disclaimer: 1. Every performance comparison on stackoverflow I read gets slammed for not being comprehensive/correct/well written/relevant etc. etc. - I'm not pretending this is a real comparison, I would just like to know how to make the Julia quicker. 2. I know the python could be optimized, implemented in Cython etc, that's not part of this discussion, it's just here for a reference of equivalent functions in Julia and Python.)</strong></p>
  
  <p>The code and performance results can been seen <a href="https://gist.github.com/samuelcolvin/7989479">in a gist</a>.</p>
  
  <p>The performance of Julia is significantly slower than Fortran. The times taken to perform the calculation itself are (50000 time steps):</p>
  
  <pre><code>Fortran: 0.051s
  Julia: 2.256s
  Python: 30.846s
  </code></pre>
  
  <p>Julia is much slower (~44 times slow) than Fortran, the gap narrows but is still significant with 10x more time steps( <code>0.50s vs 15.24s</code> ).</p>
  
  <p>These results are significantly different to those shown on <a href="http://julialang.org/">the julia home page</a>. What am I doing wrong? Could I fix the Julia to be significantly quicker?</p>
  
  <p>I've skim read the <a href="http://docs.julialang.org/en/latest/manual/performance-tips/">Julia Performance Tips</a> page and the code behind the comparison on the Julia home page and nothing is standing out to me to fix.</p>
  
  <p>Also interestingly Julia is extremely slow to load PyPlot ( <code>5secs</code> ish!!) and much slower than Python to read the text file. Could I do anything to improve these things?</p>
  
  <p>Note that the times above don't show loading time for Julia and Python, it's just the raw time taken for the computation AFAIK - see the code. For fortran it's the whole thing. The plotting has been turned off, roughly, in each case to allow speed comparison.</p>
  
  <p>Computer: Intel i7-3770, 16GB ram, SSD HD, OS: Ubuntu 13.10 64bit., Fortran: gfortran, GNU Fortran (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1, Julia: Version 0.3.0-prerelease+396 (2013-12-12 00:18 UTC), Commit c5364db* (0 days old master), x86_64-linux-gnu, Python: 2.7.5+</p>
  
  <hr>
  
  <h3>Update:</h3>
  
  <p>Based on ivarne's advice I rewrote the Julia script (updated in gist above): encapsulating grunt work in functions, declaring the type of everything and splitting different elements of matrices into different arrays where applicable. (I included Float64 in quite a few places as I tried Float32 to see if that helped, it didn't most of the time).</p>
  
  <p>The results are as follows:</p>
  
  <p><code>50,000</code> time steps:</p>
  
  <pre><code>Fortran: 0.051s (entire programme)
  Julia: raw calc.: 0.201s, calc. and return (?): 0.758s, total exec.: 6.947s
  </code></pre>
  
  <p><code>500,000</code> time steps:</p>
  
  <pre><code>Fortran: 0.495s (entire programme)
  Julia: raw calc.: 1.547s, calc. and return (?): 2.094s, total exec.: 8.521s
  </code></pre>
  
  <p>In conclusion:</p>
  
  <ul>
  <li><p>You can speed up Julia quite a bit.</p></li>
  <li><p>You can significantly affect the apparently speed of Julia depending on how you measure it's performance.</p></li>
  </ul>