reportTime: Report time

View source: R/utilities_math.R

reportTimeR Documentation

Report time

Description

Provides a nicely formatted "estimated time left" in loops plus a summary upon completion.

Usage

reportTime(
  i,
  time_start,
  nIter = NULL,
  reportEvery = NULL,
  jobs = NULL,
  prefix = ""
)

Arguments

i

current iteration

time_start

time when the loop started running

nIter

total number of iterations

reportEvery

report progress every n iterations

jobs

vector of length nIter specifying the relative difficulty of each iteration. If not NULL, estimated time left takes into account whether the jobs ahead will take more or less time than the jobs already completed

prefix

a string to print before "Done...", eg "Chain 1: "

Examples

time_start = proc.time()
for (i in 1:100) {
  Sys.sleep(i ^ 1.02 / 10000)
  reportTime(i = i, time_start = time_start, nIter = 100,
    jobs = (1:100) ^ 1.02, prefix = 'Chain 1: ')
}
## Not run: 
# Unknown number of iterations:
time_start = proc.time()
for (i in 1:20) {
  Sys.sleep(i ^ 2 / 10000)
  reportTime(i = i, time_start = time_start,
  jobs = (1:20) ^ 2, reportEvery = 5)
}

# when analyzing a bunch of audio files, their size is a good estimate
# of how long each will take to process
time_start = proc.time()
filenames = list.files('~/Downloads/temp', pattern = "*.wav|.mp3",
  full.names = TRUE)
filesizes = file.info(filenames)$size
for (i in 1:length(filenames)) {
  # ...do what you have to do with each file...
  reportTime(i = i, nIter = length(filenames),
             time_start = time_start, jobs = filesizes)
}

## End(Not run)

soundgen documentation built on Aug. 14, 2022, 5:05 p.m.