bench-package: bench: High Precision Timing of R Expressions

Description Author(s) See Also Examples

Description

Tools to accurately benchmark and analyze execution times for R expressions.

Author(s)

Maintainer: Jim Hester james.f.hester@gmail.com

Other contributors:

See Also

Useful links:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
dat <- data.frame(x = runif(10000, 1, 1000), y=runif(10000, 1, 1000))

# `bench::mark()` implicitly calls summary() automatically
results <- bench::mark(
  dat[dat$x > 500, ],
  dat[which(dat$x > 500), ],
  subset(dat, x > 500))

# However you can also do so explicitly to filter gc differently.
summary(results, filter_gc = FALSE)

# Or output relative times
summary(results, relative = TRUE)

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, ]        452µs  601µs     1445.     507KB     8.00   723
2 dat[which(dat$x > 500), ] 342µs  417µs     2194.     258KB     8.00  1097
3 subset(dat, x > 500)      606µs  743µs     1265.     510KB    12.0    633
# … with 6 more variables: n_gc <dbl>, total_time <bch:tm>, result <list>,
#   memory <list>, time <list>, gc <list>
# A tibble: 3 x 13
  expression                  min median `itr/sec` mem_alloc `gc/sec` n_itr
  <bch:expr>                <dbl>  <dbl>     <dbl>     <dbl>    <dbl> <int>
1 dat[dat$x > 500, ]         1.32   1.44      1.13      1.97     1.00   719
2 dat[which(dat$x > 500), ]  1      1         1.72      1        1     1093
3 subset(dat, x > 500)       1.77   1.78      1         1.98     1.52   627
# … 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.