Skip to content

press() is used to run 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

press(..., .grid = NULL, .quiet = FALSE)

Arguments

...

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

.grid

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

.quiet

If TRUE, progress messages will not be emitted.

Examples

# 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)
    )
  }
)
#> 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 × 16
#>    expression  rows  cols   rep      min   median `itr/sec` mem_alloc
#>    <bch:expr> <dbl> <dbl> <int> <bch:tm> <bch:tm>     <dbl> <bch:byt>
#>  1 bracket     1000    10     1  96.06µs 101.83µs     9496.  112.77KB
#>  2 which       1000    10     1  88.95µs  93.06µs    10547.   53.87KB
#>  3 subset      1000    10     1 120.66µs 125.75µs     7703.  124.63KB
#>  4 bracket    10000    10     1  326.2µs 340.62µs     2833.    1.14MB
#>  5 which      10000    10     1 265.24µs 277.69µs     3472.  575.37KB
#>  6 subset     10000    10     1  383.6µs 408.07µs     2346.    1.25MB
#>  7 bracket     1000   100     1 755.69µs  777.6µs     1254.  986.96KB
#>  8 which       1000   100     1 666.32µs 694.28µs     1418.   397.9KB
#>  9 subset      1000   100     1  785.4µs 817.13µs     1208. 1008.18KB
#> 10 bracket    10000   100     1   2.48ms   2.64ms      286.    9.71MB
#> # ℹ 14 more rows
#> # ℹ 8 more variables: `gc/sec` <dbl>, n_itr <int>, n_gc <dbl>,
#> #   total_time <bch:tm>, result <list>, memory <list>, time <list>,
#> #   gc <list>