timeIt: Times the execution of an expression

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/timeIt.R

Description

Times the execution of an expression

Usage

1
2
3
4
5
6
timeIt(
  expr,
  units = c("automatic", "seconds", "minutes", "hours", "days"),
  return.time = FALSE,
  verbose = TRUE
)

Arguments

expr

Any R expression.

units

A character expression long enough to uniquely identify one of "automatic", "seconds", "minutes", or "hours". Defaults to "automatic".

return.time

= TRUE returns the elapsed time as one of the elements in a list. See "Value" below.

verbose

= TRUE prints the elapsed time in the requested units.

Details

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.

Value

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 expr

elapsed

The elapsed time to evaluate expr

units

The time units of the elapsed time

Author(s)

Landon Sego

See Also

proc.time

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# 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")]

pnnl/Smisc documentation built on Oct. 18, 2020, 6:18 p.m.