//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> lang="en" lang="en"> David Knowles
Search Contact information
University of Cambridge Home Department of Engineering
Computational and Biological Learning Lab
University of Cambridge >  Department of Engineering >  Information Engineering  >  Computational and Biological Learning Lab  > David Knowles

Matlab vs. R performance benchmarking

A somewhat outdated comparison of Matlab and R (and a variety of other packages) can be found here. Unfortunately the R code is too outdated to run with the current (2.8.1) version but you can find a more up to date version here.

I've added five statistical functions tests to the benchmark. The Matlab code is here and the R code is here.

Set up

Each test was run twenty times on a Intel Core 2 1.86Ghz machine with 4Gb RAM running Windows Vista Business. I increased the number of repeats from three to twenty since most of the calculations rely on random numbers which will be different in each program. A much better solution for the matrix calculations would be to use the same randomly generated matrices in each program, maybe I'll do that sometime!
I was using Matlab 2008b and R 2.8.0.

What conclusions can we draw?

Matlab is still on an order of twice as fast as R for Matrix operations. Also, Matlab can sometimes workout how to vectorise loops - which is why the loop test here concludes that Matlab is 400 times faster than R! I should really write a new loop test that Matlab isn't able to vectorise! For statistical functions it is less clear cut.

Naturally, speed is not necessarily a key consideration. We'd all be using C if it was after all. Personally, I prefer R's flexible plotting, rich data structures, package management and free-ness. But I'll admit it's far from perfect. But I'll admit it's far from perfect, and Matlab does have a lot of great features (like the profiler) and clean syntax.

I. Matrix calculation R (sec) Matlab (sec) R/Matlab
Creation, transp., deformation of a 1500x1500 matrix 0.371 0.175 2.114
800x800 normal distributed random matrix 1000 0.179 0.135 1.323
Sorting of 2,000,000 random values 0.421 0.354 1.189
700x700 cross-product matrix 0.543 0.069 7.891
Linear regression over a 600x600 matrix 0.416 0.063 6.654
II. Matrix functions


FFT over 800,000 random values 0.443 0.129 3.441
Eigenvalues of a 320x320 random matrix 0.378 0.452 0.835
Determinant of a 650x650 random matrix 0.157 0.065 2.399
Cholesky decomposition of a 900x900 matrix 0.256 0.087 2.954
Inverse of a 400x400 random matrix 0.105 0.047 2.223
III. Programmation


750,000 Fibonacci numbers calculation (vector calc) 0.349 0.292 1.195
Creation of a 2250x2250 Hilbert matrix (matrix calc) 0.575 0.269 2.137
Grand common divisors of 70,000 pairs (recursion) 0.470 0.075 6.230
Creation of a 220x220 Toeplitz matrix (loops) 0.290 0.001 402.108
Escoufier's method on a 37x37 matrix (mixed) 0.550 0.636 0.865
IV. Statistics


Generating 107 uniform(0,1) random numbers 1.136 0.338 3.364
Create a permutation of [1..106 ] 0.078 0.257 0.304
Sample from binomal(100,.5) 105 times 0.061 0.480 0.126
Sample from N(0,1) 106 times 0.334 0.036 9.163
Evaluate N(0,1) at 106 locations 0.558 0.077 7.240

© University of Cambridge, Department of Engineering
Information provided by David Knowles (dak33)