Wrap a function with a timer.

time_it(func, units = "auto", digits = 2)

Arguments

func

(function) A function to decorate.

units

(character) Units in which the results are desired, including: "auto", "secs", "mins", "hours", "days", and "weeks". See difftime.

digits

(integer) The number of significant digits to be used. See signif.

Value

(closure) An object that contains the original function bound to the environment of the decorator.

Examples

Sys.sleep <- time_it(base::Sys.sleep)
Sys.sleep(0.1)
#> Time difference of 0.14 secs