I'm looking for a way to store running times in a variable in R. In MATLAB one can do something along the lines:
tic;
...
x=toc;
and then the running time is stored in the variable x. I have tried doing the same thing with the tic() toc() function in R coming from the MATLAB-package without success. Furthermore I can't see how this can be done using the system.time() function of R neither. Any help here is much appreciated.
More similar to tic
and toc
and sometimes handier e.g. for status messages in loops:
start <- Sys.time ()
do.something ()
Sys.time () - start
Use the built-in system.time
function:
tm1 <- system.time(
{
#your code here
})
or, alternatively the benchmark
function from rbenchmark
package:
tm2 <- benchmark(
{
#your code here
}, replications=1)
Or you can do as it is described in the 'tictoc' package.
tic("timer")
1+1
toc(log = TRUE, quiet = TRUE)
log.txt <- tic.log(format = TRUE)
tic.clearlog()
your output is then stored in log.txt. You can unlist(log.txt)
and analyse it as a string if you only want the time in seconds.
Cheers,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With