Re:R beats Python, R beats Julia, Anyone else wanna challeng...
by StefanKarpinski on Thursday May 22, 2014 @07:12PM
(#7787134)
I decided to do some timing comparisons against the given R implementation on my system so that we have some numbers. The minimum time rw(1000000) takes in R is 0.02 seconds – sometimes it's 2x or 3x that, probably because GC kicks in. The vectorized Julia version above takes 0.01 seconds minimum – twice as fast as R – but often it's 2.5x slower than that, also because of GC. Here's a stab at what an obvious iterative random walk implementation might look like in Julia:
function rwi(n)
a = Array(Int,n)
s = 0
for i = 1:n
s += ifelse(randbool(), -1, 1)
a[i] = s
end
return a
end
rwi(1000000) takes 0.005 seconds. That's twice as fast as the vectorized Julia version and 4x faster than R. It also allocates much less memory than either one – just the output array. For 100000000 steps, R takes 2.717 seconds, the vectorized Julia version takes 1.52 seconds, and the iterative Julia version takes 0.6 seconds.
> This vectorized R code turned out to be much faster than the Julia code – more than 1000 times faster, in fact, in the case of simulation 1000000 steps. For 100000000 steps, Julia actually is much faster than R, but the point is that the claims made about Julia’s speed advantage are really overblown.
It's a little odd to argue that "it’s very unlikely that ... Julia will become more popular than R among data scientists" while completely dismissing Julia being "much faster than R" for bigger problems. This only makes sense if one assumes that addressing bigger problems is not of increasing importance in data science – which seems counterfactual, to say the least.
"R’s speedy vectorization features" mentioned in the article are not actually features – they are limitations. In R (and Python and Matlab), you have to write vectorized code because using a for loop is slow. In Julia, you can choose which approach is better for you and for the problem at hand. Want to write vectorized code? Not a problem. Want to use a for loop? Also not a problem. Want to use recursion? Yes, even that is ok.
I also find it interesting that the poster of this article is self-described as an "octave core dev" ;-)