Skip to contents

Start a stopwatch.

Stop a stopwatch.

Usage

tic(id = 1, start = proc.time()["elapsed"], quiet = TRUE)

toc(
  id = 1,
  msg = "Elapsed time:",
  type = "units",
  signif = 3,
  quiet = FALSE,
  ...
)

Arguments

id

Define ID if multiple tic & toc are being used.

start

Start time. Now is default.

quiet

Boolean. Quiet messages?

msg

Character. Custom message shown

type

Character. Output format for time list element. Choose any of: units, clock, seconds.

signif

Integer. Significant digits.

...

Additional parameters.

Value

Invisible list. Contains tic (start time), toc (stop time), elapsed time and message printed.

toc returns an (invisible) list containing the time-stamps tic and toc, time in seconds and the message msg.

Examples

# Basic use (global stopwatch)
tic()
Sys.sleep(0.1)
toc()
#> Elapsed time: 0.102s

# Multiple tic tocs
tic(id = "two", quiet = FALSE)
#> Tic `id = two` start time: 2024-04-23 07:52:20.274637
Sys.sleep(0.2)
toc(id = "two")
#> Elapsed time: 0.202s

# Global is still working (id = 1)
toc(msg = "The function finished its work in")
#> The function finished its work in 0.306s