[R] comparing execition time: R vs matlab linear algebra...

Rick Reeves reeves at nceas.ucsb.edu
Wed Apr 19 23:00:18 CEST 2006


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

Rick Reeves	
Scientific ProgrammerAnalyst
National Center for Ecological Analysis and Synthesis (NCEAS)
University of California, Santa Barbara
reeves at nceas.ucsb.edu
805 892 2533

More information about the R-help mailing list