功能执行时间的R是否有标准化的测量方法?
很明显,我可以在执行之前和之后使用system.time,然后了解它们之间的区别,但是我想知道是否有某种标准化的方法或功能(不想发明轮子)。
我似乎记得我曾经使用过这样的东西:
somesysfunction("myfunction(with,arguments)")
> Start time : 2001-01-01 00:00:00 # output of somesysfunction
> "Result" "of" "myfunction" # output of myfunction
> End time : 2001-01-01 00:00:10 # output of somesysfunction
> Total Execution time : 10 seconds # output of somesysfunction发布于 2013-07-23 06:00:40
另一种可能的方法是使用Sys.time():
start.time <- Sys.time()
...Relevent codes...
end.time <- Sys.time()
time.taken <- end.time - start.time
time.taken与上面提到的方法相比,这并不是最优雅的方法,但绝对是一种方法。
发布于 2011-06-07 08:01:58
内置函数system.time()将执行此操作。
使用方式:system.time(result <- myfunction(with, arguments))
发布于 2011-06-07 10:01:11
正如Andrie所说,system.time()工作得很好。对于简短的函数,我更喜欢将replicate()放在其中:
system.time( replicate(10000, myfunction(with,arguments) ) )https://stackoverflow.com/questions/6262203
复制相似问题