在 R 中测量函数执行时间 [英] Measuring function execution time in R
本文介绍了在 R 中测量函数执行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
R 中是否有测量函数执行时间的标准化方法?
Is there a standardized way in R of measuring execution time of function?
显然我可以在执行前后取 system.time
然后取它们的差异,但我想知道是否有一些标准化的方式或功能(不想发明轮).
Obviously I can take system.time
before and after execution and then take the difference of those, but I would like to know if there is some standardized way or function (would like to not invent the wheel).
我好像记得我曾经使用过类似下面的东西:
I seem to remember that I have once used something like below:
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
推荐答案
另一种可能的方法是使用 Sys.time():
Another possible way of doing this would be to use Sys.time():
start.time <- Sys.time()
...Relevent codes...
end.time <- Sys.time()
time.taken <- end.time - start.time
time.taken
与上面的回答相比,这不是最优雅的方法,但绝对是一种方法.
Not the most elegant way to do it, compared to the answere above , but definitely a way to do it.
这篇关于在 R 中测量函数执行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文