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.
press(..., .grid = NULL)
If named, parameters to define, if unnamed the expression to run. Only one unnamed expression is permitted.
A pre-built grid of values to use, typically a data.frame or tibble. This is useful if you only want to benchmark a subset of all possible combinations.
# 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
#> Warning: Some expressions had a GC in every iteration; so filtering is disabled.
#> 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 `gc/sec`
#> <bch:expr> <dbl> <dbl> <int> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl>
#> 1 bracket 1000 10 1 122.41µs 182µs 5756. 115.85KB 24.2
#> 2 which 1000 10 1 97.71µs 156µs 6971. 56.01KB 22.4
#> 3 subset 1000 10 1 143.35µs 152µs 6486. 127.71KB 22.4
#> 4 bracket 10000 10 1 813.35µs 832µs 1137. 1.13MB 45.5
#> 5 which 10000 10 1 414µs 421µs 2341. 568.66KB 21.9
#> 6 subset 10000 10 1 929.9µs 949µs 1048. 1.24MB 49.9
#> 7 bracket 1000 100 1 868.19µs 894µs 1055. 1.01MB 52.7
#> 8 which 1000 100 1 747.58µs 774µs 1285. 428.73KB 23.4
#> 9 subset 1000 100 1 941.09µs 971µs 1020. 1.03MB 23.2
#> 10 bracket 10000 100 1 9.62ms 10ms 98.2 9.77MB 98.2
#> # … 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>