atime {atime}R Documentation

Asymptotic timing

Description

Computation time and memory for several R expressions of several different data sizes.

Usage

atime(
N, setup, expr.list=NULL, times=10, seconds.limit=0.01, verbose=FALSE,
result=FALSE, ...)

Arguments

N

numeric vector of at least two data sizes, default is 2^seq(2,20).

setup

expression to evaluate for every data size, before timings.

expr.list

named list of expressions to time.

times

number of times to evaluate each timed expression.

seconds.limit

if the median timing of any expression exceeds this many seconds, then no timings for larger N are computed.

verbose

logical, print messages after every data size?

result

logical, save each result?

...

named expressions to time.

Details

Each iteration involves first computing the setup expression, and then computing several times the ... expressions. For convenience, expressions may be specified either via code (...) or data (expr.list arg).

Value

list of class atime with elements seconds.limit (numeric input param), measurements (data table of results).

Author(s)

Toby Dylan Hocking

Examples


## Example 1: polynomial and exponential time string functions.
string.result <- atime::atime(
  N=unique(as.integer(10^seq(0,3.5,l=100))),
  setup={
    subject <- paste(rep("a", N), collapse="")
    pattern <- paste(rep(c("a?", "a"), each=N), collapse="")
  },
  seconds.limit=0.001,
  PCRE.match=regexpr(pattern, subject, perl=TRUE),
  TRE.match=regexpr(pattern, subject, perl=FALSE),
  constant.replacement=gsub("a","constant size replacement",subject),
  linear.replacement=gsub("a",subject,subject))
plot(string.result)

## Example 2: split data table vs frame, constant factor difference.
library(data.table)
split.result <- atime::atime(
  setup={
    set.seed(1)
    DT <- data.table(
      x1 = rep(c("c","d"), l=N),
      x2 = rep(c("x","y"), l=N),
      x3 = rep(c("a","b"), l=N),
      y = rnorm(N)
    )[sample(.N)]
    DF <- as.data.frame(DT)
  },
  seconds.limit=0.001,
  frame=split(DF[names(DF) != "x1"], DF["x1"], drop = TRUE),
  table=split(DT, by = "x1", keep.by = FALSE, drop = TRUE)
)
plot(split.result)


[Package atime version 2024.3.5 Index]