mark: Benchmark a series of functions

Description Usage Arguments Value See Also Examples

View source: R/mark.R

Description

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.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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()
)

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 and results are not stored. If check is a function that function will be called with each pair of results to determine consistency.

memory

If TRUE (the default when R is compiled with memory profiling), track memory allocations using. If FALSE disable memory tracking.

filter_gc

If TRUE remove iterations that contained at least one garbage collection before summarizing. If TRUE but an expression had a garbage collection in every iteration, filtering is disabled, with a warning.

relative

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

time_unit

If NULL the times are reported in a human readable fashion depending on each value. If one of 'ns', 'us', 'ms', 's', 'm', 'h', 'd', 'w' the time units are instead expressed as nanoseconds, microseconds, milliseconds, seconds, hours, minutes, days or weeks respectively.

exprs

A list of quoted expressions. If supplied overrides expressions defined in ....

env

The environment which to evaluate the expressions

Value

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

See Also

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

Examples

1
2
3
4
5
6
7
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))

Example output

# 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, ]        32.7µs 36.7µs    21327.  136.64KB     21.7  1966
2 dat[which(dat$x > 500), ] 33.4µs 37.8µs    21038.    2.82KB     33.3  1896
3 subset(dat, x > 500)        59µs 66.3µs    12920.   24.12KB     21.4  1209
# … with 6 more variables: n_gc <dbl>, total_time <bch:tm>, result <list>,
#   memory <list>, time <list>, gc <list>

bench documentation built on March 26, 2020, 6:32 p.m.