R/stopwatch.R

tic <- function(gcFirst = TRUE, type=c("elapsed", "user.self", "sys.self")) {
  type <- match.arg(type)
  assign(".type", type, envir=baseenv())
  if(gcFirst) gc(FALSE)
  tic <- proc.time()[type]         
  assign(".tic", tic, envir=baseenv())
  invisible(tic)
}

toc <- function() {
  type <- get(".type", envir=baseenv())
  toc <- proc.time()[type]
  tic <- get(".tic", envir=baseenv())
  print(toc - tic)
  invisible(toc)
}

stopwatch <- function() {
  tic()
  cat("The stopwatch has started. \n Press [enter] to stop it.")
  line <- readline()
  toc()
}
mobilizingcs/MobilizePrime documentation built on May 23, 2019, 5:07 a.m.