File: timetaken.R

package info (click to toggle)
r-cran-data.table 1.12.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 13,084 kB
  • sloc: ansic: 12,667; sh: 13; makefile: 6
file content (15 lines) | stat: -rw-r--r-- 510 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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)")
}