在基准测试过程中多次运行R中的函数 [英] Running functions in R multiple times during benchmarking
本文介绍了在基准测试过程中多次运行R中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使用 system.time()
来测量R中函数的计算时间。
我想运行该函数几百次以获得平均值,但我不希望
复制和粘贴多次。有没有更简单的方法来做到这一点?
I am trying to measure the computation time of a function in R using system.time()
.
I want to run the function a few hundred times to get an average but I don't want
to copy and paste that many times. Is there an easier way to do that?
推荐答案
microbenchmark包采用,times =
选项,并有更多精确度的额外奖励。
The microbenchmark package takes a ,times=
option and has the added bonus of being a bit more accurate.
> library(microbenchmark)
> m <- microbenchmark( seq(10)^2, (1:10)^2, times=10000)
> m
Unit: nanoseconds
expr min lq median uq max
1 (1:10)^2 2567 3423 3423 4278 41918
2 seq(10)^2 44484 46195 46195 47051 1804147
> plot(m)
对ggplot2使用尚未发布的autoplot()方法:
And using the not-yet-released autoplot() method for ggplot2:
autoplot(m)
这篇关于在基准测试过程中多次运行R中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文