@@ -35,7 +35,7 @@ test.data.table = function(script="tests.Rraw", verbose=FALSE, pkg=".", silent=F
3535 if (identical(script ," *.Rraw" )) {
3636 # nocov start
3737 scripts = dir(fulldir , " *.Rraw.*" )
38- scripts = scripts [! grepl(" bench|other|manual " , scripts )]
38+ scripts = scripts [! grepl(" bench|other" , scripts )]
3939 scripts = gsub(" [.]bz2$" ," " ,scripts )
4040 return (sapply(scripts , function (fn ) {
4141 err = try(test.data.table(script = fn , verbose = verbose , pkg = pkg , silent = silent , showProgress = showProgress , testPattern = testPattern ))
@@ -580,89 +580,3 @@ test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,no
580580}
581581
582582anyNonAscii = function (x ) anyNA(iconv(x , to = " ASCII" )) # nocov
583-
584- # nocov start
585- is.AsIs = function (x ) inherits(x , " AsIs" )
586- benchmark = function (num , expr , limit , tolerance = 0.025 , verbose = FALSE ) {
587-
588- .test.data.table = exists(" nfail" , parent.frame()) # test() can be used inside functions defined in tests.Rraw, so inherits=TRUE (default) here
589- numStr = sprintf(" %.8g" , num )
590- if (.test.data.table ) {
591- prevtest = get(" prevtest" , parent.frame())
592- nfail = get(" nfail" , parent.frame())
593- whichfail = get(" whichfail" , parent.frame())
594- assign(" ntest" , get(" ntest" , parent.frame()) + 1L , parent.frame(), inherits = TRUE ) # bump number of tests run
595- lasttime = get(" lasttime" , parent.frame())
596- timings = get(" timings" , parent.frame())
597- memtest = get(" memtest" , parent.frame())
598- inittime = get(" inittime" , parent.frame())
599- filename = get(" filename" , parent.frame())
600- foreign = get(" foreign" , parent.frame())
601- showProgress = get(" showProgress" , parent.frame())
602- time = nTest = NULL # to avoid 'no visible binding' note
603- on.exit( {
604- now = proc.time()[3L ]
605- took = now - lasttime # so that prep time between tests is attributed to the following test
606- assign(" lasttime" , now , parent.frame(), inherits = TRUE )
607- timings [ as.integer(num ), `:=`(time = time + took , nTest = nTest + 1L ), verbose = FALSE ]
608- } )
609- if (showProgress )
610- cat(" \r Running benchmark id" , numStr , " " )
611- } else {
612- # not `test.data.table` but developer running tests manually; i.e. `cc(F); test(...)`
613- memtest = FALSE
614- filename = NA_character_
615- foreign = FALSE
616- showProgress = FALSE
617- }
618-
619- sub.expr = substitute(expr )
620- stopifnot(is.call(sub.expr ))
621- l = if (limit.call <- is.call(sub.limit <- substitute(limit ))) system.time(limit )[[" elapsed" ]]
622- else if (is.numeric(limit )) limit
623- else stop(" limit must be constant numeric or a call to time it" )
624-
625- t = system.time(expr )[[" elapsed" ]]
626-
627- fail = FALSE
628- if (.test.data.table ) {
629- if (num < prevtest + 0.0000005 ) {
630- cat(" Test id" , numStr , " is not in increasing order\n " )
631- fail = TRUE
632- }
633- assign(" prevtest" , num , parent.frame(), inherits = TRUE )
634- }
635- if (! fail ) {
636- if (length(tolerance )== 1L ) {
637- fail = if (is.AsIs(tolerance )) {
638- t > l + tolerance
639- } else {
640- t > l * (1 + tolerance )
641- }
642- } else if (length(tolerance )== 2L ) { # # absolute difference, test 655
643- if (tolerance [1 ] > = tolerance [2 ])
644- stop(" invalid use of tolerance argument, first element must be smaller than second one, first usually being negative and second positive" )
645- fail = if (is.AsIs(tolerance )) {
646- t < l + tolerance [1 ] || t > l + tolerance [2 ]
647- } else {
648- t < l * (1 + tolerance [1L ]) || t > l * (1 + tolerance [2 ])
649- }
650- } else stop(" tolerance must be length 1 or 2" )
651- if (fail || verbose ) {
652- cat(sprintf(" Benchmark %s %scheck that expression:\n > " ,
653- numStr , if (fail ) " failed to " else " " ))
654- print(sub.expr )
655- cat(" # elapsed: " , t , " \n " , sep = " " )
656- cat(sprintf(" computes within given limit and tolerance (%s):\n > " ,
657- paste(sprintf(" %.3f%s" , tolerance , if (is.AsIs(tolerance )) " s" else " " ), collapse = " ," )))
658- if (limit.call ) print(sub.limit ) else cat(limit , " \n " , sep = " " )
659- cat(" # elapsed: " , l , " \n " , sep = " " )
660- }
661- }
662- if (fail && .test.data.table ) {
663- assign(" nfail" , nfail + 1L , parent.frame(), inherits = TRUE )
664- assign(" whichfail" , c(whichfail , numStr ), parent.frame(), inherits = TRUE )
665- }
666- invisible (! fail )
667- }
668- # nocov end
0 commit comments