Julia vs Octave vs Matlab


Jump to: navigation, search

Here is a very simple benchmark comparing the speed of Julia, Octave and Matlab. The benchmark consists in averaging the wind speed for the year 2000 of the CCMP winds from ftp://podaac-ftp.jpl.nasa.gov/allData/ccmp/L3.0/flk/2000/. The file are already download and decompressed. The data is stored in the NetCDF format:


Octave and Matlab code

ncfile = loadlist('list.txt'); % custom function to load a file as a cell array
uwnd = 0;
vwnd = 0;

for i = 1:length(ncfile); 
    uwnd = uwnd + mean(ncread(ncfile{i},'uwnd'),3);
    vwnd = vwnd + mean(ncread(ncfile{i},'vwnd'),3);

uwnd = uwnd/length(ncfile);
vwnd = vwnd/length(ncfile);

save ccmp_mean_2000_oct.mat uwnd vwnd

Julia code

Per default, Julia's does not autoscale the variable. Therefore a function ncload has been created which returns always a variable in double precision.

using NetCDF
using MAT

function ncload(fname,vname)
    x = ncread(fname,vname);
    scale_factor = ncgetatt(fname,vname,"scale_factor");
    add_offset = ncgetatt(fname,vname,"add_offset")    

    scale_factor = convert(Float64,scale_factor) 

    x = add_offset + scale_factor * x;

# load list of file
# chomp is necessary to remove newlines
f = open("list.txt")
ncfiles = map(x->chomp(x),readlines(f))

uwnd = 0
vwnd = 0

for i = ncfiles; 
    uwnd = uwnd + mean(ncload(i,"uwnd"),3);
    vwnd = vwnd + mean(ncload(i,"vwnd"),3);

uwnd = uwnd/length(ncfiles);
vwnd = vwnd/length(ncfiles);

file = matopen("ccmp_mean_2000.mat", "w")
write(file, "uwnd", uwnd)
write(file, "vwnd", vwnd)


Benchmark is performed on a ubuntu 14.04 machine (64-bit) with Intel Xeon E5420 processor. The data is stored on a 3TB West Digital hard drive (model number WDC WD30EZRX-00DC0B0).


I use here matlab R2013a.

>> tic;ccmp_mean;toc
Elapsed time is 52.314123 seconds.


I use here octave 3.8.1 and netcdf 1.0.7.

>> tic;ccmp_mean;toc
Elapsed time is 61.444 seconds.


I use julia version 0.3.11 (2015-07-27) and NetCDF 0.2.1.

julia> tic(); include("/home/abarth/Julia/ccmp_mean.jl"); toc()
elapsed time: 111.556452308 seconds

So matlab is the fastest and octave is a close second. Julia was about 2x time slower in this case.


  • matlab is a proprietary program, but octave (GPL) and julia (MIT) are open source.
  • this code, doesn't do something very interesting, (but it happens that you have to do something boring from time to time)


  • I wrote the NetCDF interface for octave, but I didn't do any optimization for this benchmark
  • I am new to Julia
Personal tools