Given an block of expressions in {}
workout()
individually times each
expression in the group. workout_expressions()
is a lower level function most
useful when reading lists of calls from a file.
workout(expr, description = NULL)
workout_expressions(exprs, env = parent.frame(), description = NULL)
one or more expressions to workout, use {}
to pass multiple
expressions.
A name to label each expression, if not supplied the deparsed expression will be used.
A list of calls to measure.
The environment in which the expressions should be evaluated.
workout({
x <- 1:1000
evens <- x %% 2 == 0
y <- x[evens]
length(y)
length(which(evens))
sum(evens)
})
#> # A tibble: 6 × 3
#> exprs process real
#> <bch:expr> <bch:tm> <bch:tm>
#> 1 x <- 1:1000 4µs 6.2µs
#> 2 evens <- x%%2 == 0 36.12µs 36.95µs
#> 3 y <- x[evens] 6.21µs 6.91µs
#> 4 length(y) 1.06µs 1.67µs
#> 5 length(which(evens)) 7.22µs 7.87µs
#> 6 sum(evens) 2.67µs 3.34µs
# The equivalent to the above, reading the code from a file
workout_expressions(as.list(parse(system.file("examples/exprs.R", package = "bench"))))
#> # A tibble: 6 × 3
#> exprs process real
#> <bch:expr> <bch:tm> <bch:tm>
#> 1 x <- 1:1000 3.22µs 5.01µs
#> 2 evens <- x%%2 == 0 28.55µs 29.56µs
#> 3 y <- x[evens] 7.34µs 8.11µs
#> 4 length(y) 1.05µs 1.91µs
#> 5 length(which(evens)) 12.69µs 13.35µs
#> 6 sum(evens) 2.3µs 3.1µs