diff --git a/DESCRIPTION b/DESCRIPTION index 9e93908..0c2eae2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: atime Type: Package Title: Asymptotic Timing -Version: 2026.4.2 +Version: 2026.4.5 Depends: R (>= 3.5.0) Authors@R: c( person("Toby", "Hocking", diff --git a/NEWS b/NEWS index 98d6ec7..a9610bf 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +Changes in version 2026.4.5 + +- atime() gains check arg (default FALSE), passed to bench::mark(). + Changes in version 2026.4.2 - atime_pkg() now sorts tests in facet plots to emphasize speedups, in addition to slowdowns. New pred.Nx used instead of N.factor (issue109 data and fix), as well as alternative="two.sided" instead of "greater" in t.test(). diff --git a/R/atime.R b/R/atime.R index d7743fb..e62c662 100644 --- a/R/atime.R +++ b/R/atime.R @@ -21,8 +21,8 @@ get_result_rows <- function(result.list){ } } -run_bench_mark <- function(times, sub.elist, N.env, result){ - m.list <- list(quote(bench::mark), iterations=times, check=FALSE) +run_bench_mark <- function(times, sub.elist, N.env, result, check){ + m.list <- list(quote(bench::mark), iterations=times, check=check) N.env$result.list <- list() for(expr.name in names(sub.elist)){ expr <- sub.elist[[expr.name]] @@ -36,9 +36,9 @@ run_bench_mark <- function(times, sub.elist, N.env, result){ } m.call <- as.call(m.list) N.df <- suppressWarnings(eval(m.call, N.env)) - if(result$keep){ - N.df$result <- N.env$result.list - } + N.df$result <- if(result$keep){ + N.env$result.list + }else list(NULL) N.df } @@ -74,7 +74,7 @@ check_atime_inputs <- function(N, result, elist){ list(keep=keep, fun=fun) } -atime <- function(N=default_N(), setup, expr.list=NULL, times=10, seconds.limit=0.01, verbose=FALSE, result=FALSE, N.env.parent=NULL, ...){ +atime <- function(N=default_N(), setup, expr.list=NULL, times=10, seconds.limit=0.01, verbose=FALSE, result=FALSE, N.env.parent=NULL, check=FALSE, ...){ kilobytes <- mem_alloc <- . <- sizes <- expr.name <- NULL ## above for CRAN NOTE. formal.names <- names(formals()) @@ -96,7 +96,7 @@ atime <- function(N=default_N(), setup, expr.list=NULL, times=10, seconds.limit= N.env <- new.env(parent=N.env.parent) N.env$N <- N.value eval(mc.args$setup, N.env) - N.df <- run_bench_mark(times, elist[not.done.yet], N.env, result) + N.df <- run_bench_mark(times, elist[not.done.yet], N.env, result, check) result.row.list <- get_result_rows(N.env$result.list) N.stats <- data.table( N=N.value, expr.name=not.done.yet, N.df diff --git a/man/atime.Rd b/man/atime.Rd index 92b0615..a94ff20 100644 --- a/man/atime.Rd +++ b/man/atime.Rd @@ -6,7 +6,7 @@ \usage{atime( N, setup, expr.list=NULL, times=10, seconds.limit=0.01, verbose=FALSE, - result=FALSE, N.env.parent=NULL, ...)} + result=FALSE, N.env.parent=NULL, check=FALSE, ...)} \arguments{ \item{N}{numeric vector of at least two unique data sizes, default is \code{2^seq(2,20)}.} @@ -25,7 +25,9 @@ and seconds). } \item{N.env.parent}{environment to use as parent of environment - created for each data size N, or NULL to use default parent env.} + created for each data size N, or NULL to use default parent env.} + \item{check}{logical, error if results are not all equal? (default + FALSE) Passed to \code{\link[bench]{mark}}.} \item{\dots}{named expressions to time.} } diff --git a/tests/testthat/test-CRAN.R b/tests/testthat/test-CRAN.R index f55a9c0..43673e9 100644 --- a/tests/testthat/test-CRAN.R +++ b/tests/testthat/test-CRAN.R @@ -117,6 +117,17 @@ test_that("more units defined in 1 row result", { expect_identical(names(unit.tab), c("match.len","seconds")) }) +test_that("result=FALSE and check=TRUE", { + expr.list <- atime::atime_grid(seq=seq(1,N), colon=1:N) + alist <- atime::atime(expr.list=expr.list, foo=1) + alist$measurements[, expect_identical(result, replicate(.N, NULL))] + expect_error({ + atime::atime(expr.list=expr.list, foo=1, check=TRUE) + }, "`seq` does not equal `foo`", fixed=TRUE) + alist <- atime::atime(expr.list=expr.list, check=TRUE) + alist$measurements[, expect_identical(result, replicate(.N, NULL))] +}) + test_that("result returned when some are NULL and others not", { atime.list <- atime::atime( N=10^seq(-3, 0),