R/timetaken.R

Defines functions timetaken

Documented in timetaken

timetaken = function(started.at)
{
  if (!inherits(started.at,"proc_time")) stop("Use started.at=proc.time() not Sys.time() (POSIXt and slow)")  # nocov
  format = function(secs) {
    if (secs > 60.0) {
      secs = as.integer(secs)
      sprintf("%02d:%02d:%02d", secs%/%3600L, (secs%/%60L)%%60L, secs%%60L)
    } else {
      sprintf(if (secs >= 10.0) "%.1fs" else "%.3fs", secs)
    }
  }
  tt = proc.time()-started.at  # diff all 3 times
  paste0(format(tt[3L])," elapsed (", format(tt[1L]), " cpu)")
}

Try the data.table package in your browser

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

data.table documentation built on March 7, 2023, 6:16 p.m.