Benchmark a list of quoted expressions. Each expression will always run at least twice, once to measure the memory allocation and store results and one or more times to measure timing.
mark( ..., min_time = 0.5, iterations = NULL, min_iterations = 1, max_iterations = 10000, check = TRUE, memory = capabilities("profmem"), filter_gc = TRUE, relative = FALSE, time_unit = NULL, exprs = NULL, env = parent.frame() )
Expressions to benchmark, if named the
The minimum number of seconds to run each expression, set to
Each expression will be evaluated a minimum of
Each expression will be evaluated a maximum of
Check if results are consistent. If
A list of quoted expressions. If supplied overrides expressions
The environment which to evaluate the expressions
A tibble with the additional summary columns. The following summary columns are computed
bench_expr The deparsed expression that was evaluated
(or its name if one was provided).
bench_time The minimum execution time.
bench_time The sample median of execution time.
double The estimated number of executions performed per
bench_bytes Total amount of memory allocated by R while
running the expression. Memory allocated outside the R heap, e.g. by
new directly is not tracked, take care to avoid
misinterpreting the results if running code that may do this.
double The number of garbage collections per second.
integer Total number of iterations after filtering
garbage collections (if
filter_gc == TRUE).
double Total number of garbage collections performed over all
iterations. This is a psudo-measure of the pressure on the garbage collector, if
it varies greatly between to alternatives generally the one with fewer
collections will cause fewer allocation in real usage.
bench_time The total time to perform the benchmarks.
list A list column of the object(s) returned by the
list A list column with results from
list A list column of
bench_time vectors for each evaluated
list A list column with tibbles containing the level of
garbage collection (0-2, columns) for each iteration (rows).
press() to run benchmarks across a grid of parameters.
dat <- data.frame(x = runif(100, 1, 1000), y=runif(10, 1, 1000)) mark( min_time = .1, dat[dat$x > 500, ], dat[which(dat$x > 500), ], subset(dat, x > 500))#> # A tibble: 3 x 13 #> expression min median `itr/sec` mem_alloc `gc/sec` n_itr #> <bch:expr> <bch:> <bch:> <dbl> <bch:byt> <dbl> <int> #> 1 dat[dat$x > 500, ] 23.6µs 26.2µs 36716. 4.15KB 10.8 3391 #> 2 dat[which(dat$x > 500), ] 23.8µs 26.4µs 36427. 2.77KB 10.6 3421 #> 3 subset(dat, x > 500) 39.9µs 43.3µs 22359. 5.46KB 10.6 2114 #> # … with 6 more variables: n_gc <dbl>, total_time <bch:tm>, result <list>, #> # memory <list>, time <list>, gc <list>