Julia is lightning fast: bubble sort revisited

I had heard the name of the new technical computing language Julia buzzing around for some time already. Now during Christmas I had some time on my hands, and implemented the bubble sort algorithm that I have already posted about several times (R, C++). The main argument for Julia is it’s speed. It claims speeds comparable to that of a compiled language such as C++, but in the form of a high-level programming language such as R or Matlab.

The following Julia code implements the bubble sort algorithm, in the same style as the C++ algorithm I implemented using Rcpp.

Running this from the command line leads to the following timings in seconds:

This is in the same order of magnitude as the C++ implementation, which leads to timings of around 0.15 secs. So, this first examples shows that Julia is comparable in speed to C++ for this example, which is much much faster than the same implementation would be in R.

Julia certainly lacks the maturity of a tool such as R or Python, but the speed is impressive and I like the clean looking syntax. I’m curious to see where Julia will go from here, but I’ll certainly try and find an excuse to try Julia out for a real project.

Tagged with: ,
Posted in R stuff
5 Comments » for Julia is lightning fast: bubble sort revisited
  1. Cristóvão Sousa says:

    Hi, nice post.

    Use for i in 1:n rather than for i in [1:n], since the later allocates an array while the former uses a range object. It’s a little like the Python 2 range vs xrange. The for i in 1:n is closer to the C’s for(int i=0; i<n; ++i).


    • Cristóvão Sousa says:

      In fact, in my machine, just by replacing


      the average time goes from 0.69 to 0.29 s!

      I really would like to see the times you get with this slight change…

      Can you try it? Please… 🙂

    • Paul Hiemstra says:

      Wow, this just shows how unexperienced I am in Julia. The timings are around 0.15 for me now. Thanks!

1 Pings/Trackbacks for "Julia is lightning fast: bubble sort revisited"
  1. […] Paul Hiemstra I had heard the name of the new technical computing language Julia buzzing around for some time […]

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax