[R] System.time

Gavin Simpson gavin.simpson at ucl.ac.uk
Thu Feb 12 16:48:22 CET 2009


On Thu, 2009-02-12 at 09:42 -0500, Stavros Macrakis wrote:
> On Thu, Feb 12, 2009 at 4:28 AM, Gavin Simpson <gavin.simpson at ucl.ac.uk> wrote:
> > When I'm testing the speed of things like this (that are in and of themselves
> > very quick) for situations where it may matter, I wrap the function call in a call
> > to replicate():
> >
> > system.time(replicate(1000, svd(Mean_svd_data)))
> >
> > to run it 1000 times, and that allows me to judge how quickly the
> > function executes.
> 
> I do the same, but with a small twist:
> 
>      system.time(replicate(1000, {svd(Mean_svd_data); 0} ))
> 
> This allows the values of svd(...) to be garbage collected.
> 
> If you don't do this and the output of the timed code is large, you
> may allocate large amounts of memory (which may influence your timing
> results) or run out of memory (which will also influence your timing
> results :-) ),

Thanks for that tip Stavros. I hadn't realised that.

G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%




More information about the R-help mailing list