press: Run setup code and benchmarks across a grid of parameters

Description Usage Arguments Examples

View source: R/press.R

Description

press() is used to run bench::mark() across a grid of parameters and then press the results together.

The parameters you want to set are given as named arguments and a grid of all possible combinations is automatically created.

The code to setup and benchmark is given by one unnamed expression (often delimited by \{).

If replicates are desired a dummy variable can be used, e.g. rep = 1:5 for replicates.

Usage

1
press(..., .grid = NULL)

Arguments

...

If named, parameters to define, if unnamed the expression to run. Only one unnamed expression is permitted.

.grid

A pre-build grid of values to use, typically a data.frame or tibble. This is useful if you only want to use a subset of all possible combinations.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Helper function to create a simple data.frame of the specified dimensions
create_df <- function(rows, cols) {
  as.data.frame(setNames(
    replicate(cols, runif(rows, 1, 1000), simplify = FALSE),
    rep_len(c("x", letters), cols)))
}

# Run 4 data sizes across 3 samples with 2 replicates (24 total benchmarks)
press(
  rows = c(1000, 10000),
  cols = c(10, 100),
  rep = 1:2,
  {
    dat <- create_df(rows, cols)
    bench::mark(
      min_time = .05,
      bracket = dat[dat$x > 500, ],
      which = dat[which(dat$x > 500), ],
      subset = subset(dat, x > 500)
    )
  }
)

Example output

Running with:
   rows  cols   rep
1  1000    10     1
2 10000    10     1
3  1000   100     1
4 10000   100     1
5  1000    10     2
6 10000    10     2
7  1000   100     2
8 10000   100     2
# A tibble: 24 x 16
   expression  rows  cols   rep      min   median `itr/sec` mem_alloc `gc/sec`
   <bch:expr> <dbl> <dbl> <int> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
 1 bracket     1000    10     1 205.81µs 262.25µs    3424.    114.6KB     22.7
 2 which       1000    10     1 220.95µs 281.39µs    3118.    55.15KB     22.1
 3 subset      1000    10     1 179.94µs 200.34µs    4211.   141.93KB     21.6
 4 bracket    10000    10     1   1.07ms   1.67ms     679.     1.13MB      0  
 5 which      10000    10     1  538.7µs  590.3µs    1373.   571.49KB     21.5
 6 subset     10000    10     1   1.26ms   1.36ms     729.     1.25MB     21.4
 7 bracket     1000   100     1   1.13ms   1.32ms     762.  1012.91KB     49.1
 8 which       1000   100     1   1.04ms    1.1ms     809.   415.26KB     78.3
 9 subset      1000   100     1   1.43ms   1.54ms     631.     1.01MB     21.7
10 bracket    10000   100     1   9.65ms  10.67ms      85.8    9.76MB     28.6
 1 which       1000    10     1 205.81µs 262.25µs    3424.    114.6KB     22.7
 2 subset      1000    10     1 220.95µs 281.39µs    3118.    55.15KB     22.1
 3 bracket     1000    10     1 179.94µs 200.34µs    4211.   141.93KB     21.6
 4 which      10000    10     1   1.07ms   1.67ms     679.     1.13MB      0  
 5 subset     10000    10     1  538.7µs  590.3µs    1373.   571.49KB     21.5
 6 bracket    10000    10     1   1.26ms   1.36ms     729.     1.25MB     21.4
 7 which       1000   100     1   1.13ms   1.32ms     762.  1012.91KB     49.1
 8 subset      1000   100     1   1.04ms    1.1ms     809.   415.26KB     78.3
 9 bracket     1000   100     1   1.43ms   1.54ms     631.     1.01MB     21.7
10 which      10000   100     1   9.65ms  10.67ms      85.8    9.76MB     28.6
 1 subset      1000    10     1 205.81µs 262.25µs    3424.    114.6KB     22.7
 2 bracket     1000    10     1 220.95µs 281.39µs    3118.    55.15KB     22.1
 3 which       1000    10     1 179.94µs 200.34µs    4211.   141.93KB     21.6
 4 subset     10000    10     1   1.07ms   1.67ms     679.     1.13MB      0  
# … with 14 more rows, and 7 more variables: n_itr <int>, n_gc <dbl>,
#   total_time <bch:tm>, result <list>, memory <list>, time <list>, gc <list>

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