[R] R badly lags matlab on performance?

From: Ajay Shah <ajayshah_at_mayin.org>
Date: Sat, 03 Jan 2009 22:25:38 +0530


Here's a small R program:



a <- rep(1,10000000)

system.time(a <- a + 1)

system.time(for (i in 1:10000000) {a[i] <- a[i] + 1})


and here's its matlab version:



function forloop()

  a = ones(1e7,1);

  tic; a = a + 1; toc

  tic
  for i=1:1e7
    a(i) = a(i) + 1;
  end
  toc


The machine used for testing was an i386 core 2 duo machine at 2.2 GHz, running OS X `Tiger'. The R was 2.8.0 and the matlab was 2008a.

Here's the performance (time taken in seconds):

                        Matlab            R            Times
Vector version          0.0446            0.067        1.5x
For loop version        0.0992            42.209       425.5x

So the R is 1.5x costlier for the vector version and 425.5x costlier with matlab.

I wonder what we're doing wrong!

-- 
Ajay Shah                                      http://www.mayin.org/ajayshah  
ajayshah@mayin.org                             http://ajayshahblog.blogspot.com
<*(:-? - wizard who doesn't know the answer.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sat 03 Jan 2009 - 16:58:09 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 04 Jan 2009 - 20:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive