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, filter_gc = TRUE,
  relative = FALSE, env = parent.frame())

Arguments

...

Expressions to benchmark, if named the expression column will be the name, otherwise it will be the deparsed expression.

min_time

The minimum number of seconds to run each expression, set to Inf to always run max_iterations times instead.

iterations

If not NULL, the default, run each expression for exactly this number of iterations. This overrides both min_iterations and max_iterations.

min_iterations

Each expression will be evaluated a minimum of min_iterations times.

max_iterations

Each expression will be evaluated a maximum of max_iterations times.

check

Check if results are consistent. If TRUE, checking is done with all.equal(), if FALSE checking is disabled. If check is a function that function will be called with each pair of results to determine consistency.

filter_gc

If TRUE filter iterations that contained at least one garbage collection before summarizing.

relative

If TRUE all summaries are computed relative to the minimum execution time rather than absolute time.

env

The environment which to evaluate the expressions

Value

A tibble with the additional summary columns. The following summary columns are computed

  • min - bench_time The minimum execution time.

  • mean - bench_time The arithmetic mean of execution time

  • median - bench_time The sample median of execution time.

  • max - bench_time The maximum execution time.

  • mem_alloc - bench_bytes Total amount of memory allocated by running the expression.

  • itr/sec - integer The estimated number of executions performed per second.

  • n_itr - integer Total number of iterations after filtering garbage collections (if filter_gc == TRUE).

  • n_gc - integer Total number of garbage collections performed over all runs.

See also

press() to run benchmarks across a grid of parameters.

Examples

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 14 #> expression min mean median max `itr/sec` mem_alloc n_gc n_itr #> <chr> <bch:> <bch:t> <bch:> <bch:tm> <dbl> <bch:byt> <dbl> <int> #> 1 dat[dat$x… 64.9µs 71.7µs 69.3µs 165.18µs 13955. 4.15KB 0 1384 #> 2 dat[which… 66.5µs 74.6µs 69.7µs 1.84ms 13398. 2.77KB 1 1262 #> 3 subset(da… 93.9µs 101.7µs 98.2µs 173.28µs 9835. 5.46KB 1 930 #> # ... with 5 more variables: total_time <bch:tm>, result <list>, memory <list>, #> # time <list>, gc <list>