[R] comparing execition time: R vs matlab linear algebra...
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Apr 20 08:38:08 CEST 2006
You haven't told us your platform. On most platforms, R does not
build/ship with an optimized BLAS, and this can make a big difference to
execution times of such problems. See the R-admin manual.
Beyond that, qr/qr.coef is not the most obvious way to solve linear
systems (solve is), and the option LAPACK=TRUE will be faster, not least
because it can make better use of an optimzed BLAS.
And yes, if `sparse' is a form of sparseness that packages can exploit, it
will help to use them, and you must be using sparseness in Matlab to even
be able to store the matrices.
R is not a numerical linear algbra system and does not intend to compete
with say Octave. Rather, it aims to have enough facilities that in almost
all uses of R, the slowness of linear algebra is not the limiting factor.
I do wonder why you are porting Matlab scripts to R if Matlab can handle
On Wed, 19 Apr 2006, Rick Reeves wrote:
> We are evaluating the performance of R matrix algebra es as we port a
> MATLAB R14 script into R.
> The MATLAB code basically evaluates the AX=B system on sparse matrices
> that result in output matrices of 100 to 1,000,000 rows/columns.
> Our R prototype script uses spase base matrices and the methods qr() and
> The following statements are called inside a doubly-nested loop:
> G is an n x m sparse matrix with most nonzero values near the main diagonal,
> CURR is an n x 1 vector:
> the MATALAB script:
> P = G \ CURR; % matrix left-divide
> QG = qr(G)
> P = qr.coef(QG, CURR)
> The answer we get matches that of the MATLAB code for small (60x60)
> But, execution times are much longer (40 minutes, compared to 2 minutes for
> the MATLAB script)
> Also, the R version cannot accommodate a solution matrix greater than
> aprox 10,000 x 10,000 elements,while the MATLAB script has generated
> solutions for 10**6 x 10**6 solution matrices.
> My questions: 1) Have others noticed this difference in performance
> between R and MATLAB?
> 2) Is there R literature (I have searched, not
> found) that discusses optimizing these
> solutions in R? such as.....
> 2) Would developing a solution using the Matrix or
> SparseM classes improve performance?
> Thanks in advance for any insights!
> Rick R
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help