# 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)
)
}
)
Run the code above in your browser using DataLab