[R] variations in how long commands take

David Kane <David Kane a296180 at mica.fmr.com
Tue Jul 17 19:58:12 CEST 2001

We are performming a series of S+ 6.0 versus R 1.3 comparisons. (If anyone has
already written scripts for this purpose, we would be eager for a copy.) The
purpose is to see if there are any "gotchas" -- places were S+ works and R
doesn't -- that would prevent us from going all the way over to R. (We have
lots of legacy code, so the conversion costs are non-trivial.) As part of this
project, we have some simple matrix code that takes a similar amount of time in
S+ and in R (with R a little faster) the *first* time that we run it. However,
repeated invocations of this code in R produce slower and slower times (often
dramatically so). Here is a simple example (with a new R session):

> version
platform sparc-sun-solaris2.6
arch     sparc               
os       solaris2.6          
system   sparc, solaris2.6   
major    1                   
minor    3.0                 
year     2001                
month    06                  
day      22                  
language R                   

> m <- matrix(1, 400, 40000)
> proc.time(x0 <- apply(m, 2, sum))
[1] 21.88  3.16 40.13  0.00  0.00

So far, so good. This is more than twice as fast as the same thing in S+
6.0. But when I re-issue this command, I get:

> proc.time(x0 <- apply(m, 2, sum))
[1] 37.09  4.65 63.13  0.00  0.00
> proc.time(x0 <- apply(m, 2, sum))
[1] 52.34  5.44 85.29  0.00  0.00

So, my first question is: Why do the times keep going up? I first assumed that
there were some problems with overwriting x0 again and again, but I then remove
everything from the workspace and start "fresh":

> remove(list = ls())
> ls()
> m <- matrix(1, 400, 40000)
> proc.time(x0 <- apply(m, 2, sum))
[1]  72.50   6.13 137.08   0.00   0.00

Second question is: Why does this continue even with an empty workspace? I do
not see this behavior in S+.

I have read ?Memory and played around with things like gc() and mem.limits(). I
am aware that R and S+ are very different in their memory usage. But I suspect
that there is something fundamental about R that I am missing . . .

Any suggestions or pointers would be much appreciated.


Dave Kane
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list