R/tictoc.R

Defines functions toc tic

Documented in tic toc

###
### TICTOC.R - Stopwatch timer
###


##-----------------------------------------------------------------------------
tic <- function(gcFirst = FALSE) {
    if (gcFirst == TRUE) {
        gc(verbose = FALSE)
    }
    assign("elapsedTime", proc.time()[3], envir = .pracmaEnv)
    invisible()
}


##-----------------------------------------------------------------------------
toc <- function(echo = TRUE) {
    prevTime <- get("elapsedTime", envir = .pracmaEnv)
    diffTimeSecs <- proc.time()[3] - prevTime
    if (echo) {
        cat(sprintf("elapsed time is %f seconds", diffTimeSecs), "\n")
        return(invisible(diffTimeSecs))
    } else {
        return(diffTimeSecs)
    }
}

Try the pracma package in your browser

Any scripts or data that you put into this service are public.

pracma documentation built on March 19, 2024, 3:05 a.m.