[R] Quirks with system.time and simulations

Thomas Lumley tlumley at u.washington.edu
Mon Jun 14 16:08:18 CEST 2004


On Mon, 14 Jun 2004, Patrick Connolly wrote:
>
> It seems as though the first simulation makes it "easier" for
> subsequent simulations of the same type AND also for simulations of a
> somewhat different type also.  The degree to which it "helps" varies
> according to just what is being run (no surprise there).  What I can't
> figure out is what is happening that makes it quicker for second and
> subsequent runs.
>

Luke Tierney would be the person most likely to have a definitive answer,
but my guess is that it is because of the generational garbage collector.
When this was added the speed of R improved about 20%, and the main reason
is that most garbage collections involve only recently allocated memory.
One effect is that memory blocks tend to get reused for the same objects
in later iterations of the simulation, which is more efficient.  For the
second simulation the gains are smaller.

Possibly a more accurate benchmark would be something like

Rprof("timing.prof")
replicate(LOTS, {oneway(); otherway()})
Rprof(NULL)
summaryRprof("timing.prof")

interleaving the two methods.


	-thomas




More information about the R-help mailing list