# simple example where we time the execution of some elements in a function
# we trigger the message conditionally on the value of the argument `debug`.
rnorm_crossprod = function(n, mean = 0, sd = 1, debug = FALSE){
# we set the timer
timer_magic()
# we compute some stuff
x = rnorm(n, mean, sd)
# we can report the time with .timer
message_magic("{15 align ! Generation}: {.timer}", .trigger = debug)
res = x %*% x
message_magic("{15 align ! Product}: {.timer}",
"{15 align ! Total}: {.timer_total}",
.sep = "\n", .trigger = debug)
res
}
rnorm_crossprod(1e5, TRUE)
Run the code above in your browser using DataLab