[R] R badly lags matlab on performance?

Dirk Eddelbuettel edd at debian.org
Sun Jan 4 01:44:12 CET 2009


On 3 January 2009 at 18:02, luke at stat.uiowa.edu wrote:
| The current byte code compiler available from my web site speeds this
| (highly artificial) example by about a factor of 4.  The experimental
| byte code engine I am currently working on (and that can't yet do much
| more than an example like this) speeds this up by a factor of
| 80. Whether that level of improvement (for toy examples like this)
| will remain once the engine is more complete and whether a reasonable
| compiler can optimize down to the assembly code I used remain to be
| seen.

Stephen Milborrow's jit compiler and Ra variant -- for which the R 2.8.1
version was released today -- already delivers improvements somewhere near
the middle of 'four' to 'eighty' times:

edd at ron:~> R --slave < /tmp/ajayshah.R
   user  system elapsed
  0.052   0.056   0.109
   user  system elapsed
 68.984   0.088  69.384
edd at ron:~> Ra --slave < /tmp/ajayshah.Ra
   user  system elapsed
  0.096   0.068   0.162
   user  system elapsed
   2.06    0.10    2.16
edd at ron:~> diff -u /tmp/ajayshah.R*
--- /tmp/ajayshah.R     2009-01-03 11:05:03.000000000 -0600
+++ /tmp/ajayshah.Ra    2009-01-03 18:37:20.000000000 -0600
@@ -2,4 +2,4 @@

 system.time(a <- a + 1)

-system.time(for (i in 1:10000000) {a[i] <- a[i] + 1})
+system.time({ jit(1); for (i in 1:10000000) {a[i] <- a[i] + 1} })
edd at ron:~>

The vectorised example shows highly variable times anywhere between 0.11 to
0.17 seconds so taking ratios is speculative.  Either way, you can get a
speedup of maybe 30 times by switching to a just-in-time compiler for R and
adding an additional function call.

Dirk

-- 
Three out of two people have difficulties with fractions.




More information about the R-help mailing list