Last active
February 13, 2022 23:00
-
-
Save jimjam-slam/cdcd36c6ea779fab6932 to your computer and use it in GitHub Desktop.
Returns the time elapsed since the script was sourced. Great for profiling! Source it at the start of your script, then call run.time() when outputting debug info #rstatstips
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# james goldie, climate change research centre, unsw, dec 2015 | |
# run.time: returns the time elapsed since this script was | |
# sourced in sensible units as a string ('**h**m**s') | |
script.start.time = Sys.time() | |
run.time <- function() | |
{ | |
now = Sys.time() | |
return(paste0( | |
as.integer(difftime(now, script.start.time, units = 'hours')), | |
'h', | |
as.integer(difftime(now, script.start.time, units = 'mins')) %% 60, | |
'm', | |
as.integer(difftime(now, script.start.time, units = 'secs')) %% 60, | |
's ')) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment