| name | microbenchmark |
| description | R microbenchmark package for precise timing. Use for sub-millisecond accurate timing of R expressions. |
microbenchmark
Accurate timing functions.
Basic Usage
library(microbenchmark)
microbenchmark(
sqrt(x),
x^0.5,
exp(log(x)/2)
)
Options
microbenchmark(
sqrt(x),
x^0.5,
times = 100,
unit = "ms",
check = "equal",
control = list(
order = "random",
warmup = 10
)
)
Named Expressions
microbenchmark(
"sqrt" = sqrt(x),
"power" = x^0.5,
"exp_log" = exp(log(x)/2)
)
Setup Code
microbenchmark(
sort(x),
order(x),
setup = {
x <- runif(1000)
}
)
Results
results <- microbenchmark(
sqrt(x),
x^0.5
)
summary(results)
as.data.frame(results)
print(results, unit = "ms")
Plotting
library(ggplot2)
autoplot(results)
boxplot(results)
autoplot(results) +
geom_violin()
Compare Functions
f1 <- function(x) sum(x)
f2 <- function(x) Reduce(`+`, x)
x <- 1:1000
microbenchmark(
f1(x),
f2(x)
)
Time Units
print(results, unit = "relative")
Statistical Summary
results <- microbenchmark(expr1, expr2)
summary(results)$min
summary(results)$mean
summary(results)$median
summary(results)$max
summary(results)$neval