timeIt {Smisc} | R Documentation |
Times the execution of an expression
timeIt(expr, units = c("automatic", "seconds", "minutes", "hours", "days"), return.time = FALSE, verbose = TRUE)
expr |
Any R |
units |
A character expression long enough to uniquely identify one of "automatic", "seconds", "minutes", or "hours". Defaults to "automatic". |
return.time |
|
verbose |
|
If units = "automatic"
, then the units are choosen according to the
following rule: If the duration is < 2 min, use seconds. Else if duration
< 2 hours, use minutes. Else if < 2 days, use hours. Otherwise, use days.
If return.time = FALSE
, invisibly returns the evaluation of
expr
. If return.time = TRUE
, invisibly returns a list with
the following components:
out |
The evaluation of |
elapsed |
The elapsed time to evaluate |
units |
The time units of the elapsed time |
Landon Sego
# We can assign the object within the call to timeIt(): timeIt(x1 <- rnorm(10^6)) str(x1) # We can just run the expression without assigning it to anything timeIt(rnorm(10^7), units = "m") # Or we can assign the result externally x2 <- timeIt(rnorm(10^7)) str(x2) # To store the elapsed time: x3 <- timeIt(rnorm(10^7), verbose = FALSE, return.time = TRUE) x3[c("elapsed","units")]