以R为单位的运行时间-最小值,最大值

以R为单位的运行时间-最小值,最大值,r,elapsedtime,R,Elapsedtime,我需要比较两个函数的运行时间。目前,我正在使用以下代码: system.time(f1()) system.time(f2()) 如果我想多次运行相同的函数,我会使用: system.time(replicate(10, f1())) system.time(replicate(10, f2())) 我从system.time获得的信息是用户、系统和经过的时间 关键是,如果我复制这个函数,我会知道单个调用的最小和最大运行时间 我该怎么办?如果您不受仅使用base软件包的限制,我建议您使用软件

我需要比较两个函数的运行时间。目前,我正在使用以下代码:

system.time(f1())
system.time(f2())
如果我想多次运行相同的函数,我会使用:

system.time(replicate(10, f1()))
system.time(replicate(10, f2()))
我从
system.time
获得的信息是用户、系统和经过的时间

关键是,如果我复制这个函数,我会知道单个调用的最小和最大运行时间


我该怎么办?

如果您不受仅使用
base
软件包的限制,我建议您使用软件包

> f1 <- function() 1
> f2 <- function() 2
> microbenchmark::microbenchmark(f1(), f2(), times = 10)
Unit: nanoseconds
 expr min  lq  mean median  uq  max neval cld
 f1() 134 195 896.7    309 360 6418    10   a
 f2() 133 138 305.3    189 230 1320    10   a
> f1 <- function() sapply(1:100000, identity)
> times <- replicate(10, system.time(f1())[3])
> min(times)
[1] 0.051
> max(times)
[1] 0.057