powered by
Wraps a function with CLI-based timing and prints its runtime in seconds. Useful for benchmarking or logging time-consuming tasks.
with_timer(fn, name = "Task")
A function that executes fn(...) and prints timing information (returns invisibly).
fn(...)
A function to be wrapped.
A short descriptive name of the task (used in log output).
Requires the tictoc package (CLI messages are emitted via cli).
tictoc
cli
slow_fn <- function(n) { Sys.sleep(0.01); n^2 } timed_fn <- with_timer(slow_fn, name = "Square Task") timed_fn(5)
Run the code above in your browser using DataLab