Following this post I decided to benchmark Julia against GNU Octave and the results were inconsistent with the speed-ups illustrated in julialang.org.
I compiled both Julia and GNU Octave with CXXFLAGS='-std=c++11 -O3'
, the results I got:
GNU Octave
a=0.9999;
tic;y=a.^(1:10000);toc
Elapsed time is 0.000159025 seconds.
tic;y=a.^(1:10000);toc
Elapsed time is 0.000162125 seconds.
tic;y=a.^(1:10000);toc
Elapsed time is 0.000159979 seconds.
--
tic;y=cumprod(ones(1,10000)*a);toc
Elapsed time is 0.000280142 seconds.
tic;y=cumprod(ones(1,10000)*a);toc
Elapsed time is 0.000280142 seconds.
tic;y=cumprod(ones(1,10000)*a);toc
Elapsed time is 0.000277996 seconds.
Julia
tic();y=a.^(1:10000);toc()
elapsed time: 0.003486508 seconds
tic();y=a.^(1:10000);toc()
elapsed time: 0.003909662 seconds
tic();y=a.^(1:10000);toc()
elapsed time: 0.003465313 seconds
--
tic();y=cumprod(ones(1,10000)*a);toc()
elapsed time: 0.001692931 seconds
tic();y=cumprod(ones(1,10000)*a);toc()
elapsed time: 0.001690245 seconds
tic();y=cumprod(ones(1,10000)*a);toc()
elapsed time: 0.001689241 seconds
Could someone explain why Julia is slower than GNU Octave with these basic operations? After warmed, it should call LAPACK/BLAS without overhead, right?
EDIT:
As explained in the comments and answers, the code above is not a good benchmark nor it illustrates the benefits of using the language in a real application. I used to think of Julia as a faster "Octave/MATLAB", but it is much more than that. It is a huge step towards productive, high-performance, scientific computing. By using Julia, I was able to 1) outperform software in my research field written in Fortran and C++, and 2) provide users with a much nicer API.
.^
orcumprod
– are part of BLAS or LAPACK. These operations are just implemented in C as part of Octave's source and in Julia as part of Julia's base distribution. – StefanKarpinskiones(1,10000)*a
and the internals probably using Horner's rule or something. But you're right, I shouldn't have mentioned LAPACK/BLAS for this particular snippet of code, my fingers always type them unconsciously. :) – juliohm