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)
expr | one or more expressions to workout, use |
---|---|
description | A name to label each expression, if not supplied the deparsed expression will be used. |
exprs | A list of calls to measure. |
env | 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 x 3 #> exprs process real #> <bch:expr> <bch:tm> <bch:tm> #> 1 x <- 1:1000 3.9µs 6.44µs #> 2 evens <- x%%2 == 0 42.71µs 43.15µs #> 3 y <- x[evens] 5.44µs 5.96µs #> 4 length(y) 484ns 953.67ns #> 5 length(which(evens)) 4.05µs 4.29µs #> 6 sum(evens) 2.43µs 2.62µ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 x 3 #> exprs process real #> <bch:expr> <bch:tm> <bch:tm> #> 1 x <- 1:1000 2.94µs 5.72µs #> 2 evens <- x%%2 == 0 44.64µs 45.06µs #> 3 y <- x[evens] 5.75µs 6.2µs #> 4 length(y) 611ns 953.67ns #> 5 length(which(evens)) 3.73µs 4.05µs #> 6 sum(evens) 2.58µs 3.1µs