Skip to content

Instantly share code, notes, and snippets.

@micstr
Created April 28, 2020 06:33
Show Gist options
  • Save micstr/219060120b47e376a0990b37f4bd29d8 to your computer and use it in GitHub Desktop.
Save micstr/219060120b47e376a0990b37f4bd29d8 to your computer and use it in GitHub Desktop.
Logging with tictoc
# Logging use of tictoc notes
# See https://stackoverflow.com/a/47954069/4606130
# https://www.jumpingrivers.com/blog/timing-in-r/#the-tictoc-package
tic("timer")
1+1
# When log = TRUE, toc() pushes the measured timing to a list
# quiet = TRUE prevents from printing the timing
toc(log = TRUE, quiet = TRUE)
log.txt <- tic.log(format = TRUE)
tic.clearlog()
# you can unlist to look into log
#Fetch the results of toc() as formatted text for printing.
log.txt <- tic.log(format = TRUE)
#Extract the list containing measurements in raw format.
log.lst <- tic.log(format = FALSE)
#Since the data is already extracted, clear the tictoc log.
tic.clearlog()
#Convert the list elements to timings. Each element of the list has a start (tic) and end (toc) timestamp.
timings <- unlist(lapply(log.lst, function(x) x$toc - x$tic))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment