Dear List, I want to let R calculate the time (run-time) it requires to run a self-written simulation function. I tried as follows: it
enables me to see the starting and finishing time points. ############################# "sim.result" <- function(nsim, ...){ Starting <- date() ... # calculations # final.result <- ... # Output for display # cat("# of Iterations used =", nsim, "\n" ) Ending <- date() cat("Start of Program at", Starting, "\n" ) cat("End of Program at", Ending, "\n" ) return(print(final.result, quote = FALSE)) } ############################# But how about I want the results in difference of statring and ending time in seconds only (say, in output, I need the function to say that "the program took 597 secornds to run the whole simulation"), not in all these format(Sys.time(), "%a %b %d %H:%M:%S %Y") Again, I tried in the following way, but it does not seem to do the trick > starting<-Sys.time() > ending<-Sys.time() > format(diff(ending,starting), "%H:%M:%S") Error in Ops.POSIXt(lag, differences) : * not defined for "POSIXt" objects > as.numeric(format(ending, "%H:%M:%S")) [1] NA How should I proceed? Thanks for your valuable time. Thanks in advance. Mohammad Ehsanul Karim Using Windows Xp, R 2.3.1 Institute of Statistical Research and Training, University of Dhaka ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.