[R] variations in how long commands take
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Jul 17 20:25:08 CEST 2001
On Tue, 17 Jul 2001, David Kane <David Kane wrote:
> 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):
You mean system.time, nor proc.time! proc.time is the cumulative usage
of the session and can only increase. Here's my results:
> m <- matrix(1, 400, 40000)
> system.time(x0 <- apply(m, 2, sum))
[1] 6.98 1.03 17.40 0.00 0.00
> system.time(x0 <- apply(m, 2, sum))
[1] 7.02 0.44 7.55 0.00 0.00
> system.time(x0 <- apply(m, 2, sum))
[1] 6.88 0.48 7.36 0.00 0.00
>
> > version
> _
> platform sparc-sun-solaris2.6
> arch sparc
> os solaris2.6
> system sparc, solaris2.6
> status
> 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()
> character(0)
> > 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.
>
> Thanks,
>
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
--
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 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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