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)

Arguments

expr

one or more expressions to workout, use {} to pass multiple expressions.

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.

Examples

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            3.05µs   5.01µs
#> 2 evens <- x%%2 == 0    19.29µs  19.55µs
#> 3 y <- x[evens]          4.81µs   5.25µs
#> 4 length(y)               463ns 953.67ns
#> 5 length(which(evens))    5.7µs   5.96µs
#> 6 sum(evens)             1.75µs   1.91µ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.07µs   4.29µs
#> 2 evens <- x%%2 == 0    24.33µs   24.8µs
#> 3 y <- x[evens]          5.98µs   6.44µs
#> 4 length(y)               691ns   1.19µs
#> 5 length(which(evens))   5.68µs    6.2µs
#> 6 sum(evens)             2.31µs   2.86µs