# NOT RUN {
## Measure the time it takes to dispatch a simple function call
## compared to simply evaluating the constant \code{NULL}
f <- function() NULL
res <- microbenchmark(NULL, f(), times=1000L)
## Print results:
print(res)
## Plot results:
boxplot(res)
## Pretty plot:
if (require("ggplot2")) {
autoplot(res)
}
## Example check usage
my_check <- function(values) {
all(sapply(values[-1], function(x) identical(values[[1]], x)))
}
f <- function(a, b)
2 + 2
a <- 2
## Check passes
microbenchmark(2 + 2, 2 + a, f(2, a), f(2, 2), check=my_check)
# }
# NOT RUN {
a <- 3
## Check fails
microbenchmark(2 + 2, 2 + a, f(2, a), f(2, 2), check=my_check)
# }
Run the code above in your browser using DataLab