gpt4 book ai didi

r - 测量 R 中函数的执行时间

转载 作者:行者123 更新时间:2023-12-03 04:04:44 32 4
gpt4 key购买 nike

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

最佳答案

另一种可能的方法是使用 Sys.time():

start.time <- Sys.time()
...Relevent codes...
end.time <- Sys.time()
time.taken <- end.time - start.time
time.taken

与上面的答案相比,这不是最优雅的方法,但绝对是一种方法。

关于r - 测量 R 中函数的执行时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6262203/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com