The tictoc
library has convenience functions for timing code. Here’s the basic usage relative to timing with base R.
library(tictoc)
tic()
# code here
toc()
tic <- Sys.time()
# code here
toc <- Sys.time()
print(toc - tic)
Where this library excels is when you want to time multiple parts of your code. Each tic
pushes the time onto a stack and each toc
pops the most recent time from said stack. That means you don’t have to worry about assigning several timing variables even if you want to time nested code.