[R] timing a function

Gabor Grothendieck ggrothendieck at myway.com
Sun Mar 21 17:46:22 CET 2004


In rereading my post I noticed one point that may not
be clear.  When referring to using a fresh R session,
that is not an alternative to gc(), its another thing
that can be done in addition.  One should still use gc().
In fact, the garbage collector may be called several
times even during the start up of an R session and
it could still be at a point close to another garbage
collection even at start of a fresh session.


---
Date:   Sun, 21 Mar 2004 09:23:32 -0500 (EST) 
From:   Gabor Grothendieck <ggrothendieck at myway.com>
To:   <phddas at yahoo.com>, <r-help at stat.math.ethz.ch> 
Subject:   RE: [R] timing a function 

 


Just one tip in regard to the information already provided
by others.

If you time two functions to compare them and it just so happens
that a garbage collection occurs within one but not the other
then your timing will be distorted. To control for this issue
a gc() command just before each system.time command:

gc(); system.time(x <- rnorm(1000000))

That will cause a garbage collection to occur before the
code is run so that it starts out from a known state.

Another thing you could do is to try running from a fresh
R session.


Date: Sat, 20 Mar 2004 10:11:03 -0800 (PST) 
From: Fred J. <phddas at yahoo.com>
To: r help <r-help at stat.math.ethz.ch> 
Subject: [R] timing a function 


Hello
is there a way to time how long it takes to run a code
in R. somthing like tic toc in matlab as such?
help.search("timing") put out nothing.
and while I got you, debugging the code, is there a
step through and the rest of the debugging tools
working with ESS.

thanks




More information about the R-help mailing list