workout: Workout a group of expressions individually

Description Usage Arguments Examples

View source: R/workout.R

Description

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.

Usage

1
2
3
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
workout({
  x <- 1:1000
  evens <- x %% 2 == 0
  y <- x[evens]
  length(y)
  length(which(evens))
  sum(evens)
})

# The equivalent to the above, reading the code from a file
workout_expressions(as.list(parse(system.file("examples/exprs.R", package = "bench"))))

Example output

# A tibble: 6 x 3
  exprs                 process     real
  <bch:expr>           <bch:tm> <bch:tm>
1 x <- 1:1000            9.92µs   12.4µs
2 evens <- x%%2 == 0     39.2µs  40.53µs
3 y <- x[evens]         12.59µs  13.59µs
4 length(y)              2.52µs   3.34µs
5 length(which(evens))   8.59µs   9.54µs
6 sum(evens)             4.58µs   5.48µs
# A tibble: 6 x 3
  exprs                 process     real
  <bch:expr>           <bch:tm> <bch:tm>
1 x <- 1:1000            5.16µs   7.63µs
2 evens <- x%%2 == 0    33.72µs  34.81µs
3 y <- x[evens]          9.83µs  10.73µs
4 length(y)              1.11µs   1.91µs
5 length(which(evens))   8.01µs   8.82µs
6 sum(evens)             4.09µs   4.77µs

bench documentation built on March 26, 2020, 6:32 p.m.