I'm doing something like this
library(microbenchmark)
library(tidyverse)
f1 = function(n=100) rnorm(n)
f2 = function(n=100, shape1=1, shape2=0.1) rbeta(n, shape1, shape2)
f3 = function(n=100, shape=1) rgamma(n, shape)
maxdif = 1e6
mb = microbenchmark(f1(100), f2(100), f3(100), times=1)
if(max(abs(mb$time - lead(mb$time)), na.rm=TRUE)<maxdif) mb =
microbenchmark(f1(100), f2(100), f3(100), times=10)
mb$time
# [1] 1927396 1876079 1660118 32074 20528 42338 25659 23094 35923 37633
# [11] 16251 39344 27797 38061 13258 12830 38061 13685 13258 23094
# [21] 13686 25232 37633 24377 20528 12830 38061 14113 12402 35495
So far, everything is clear to me and as expected. However, if I enclose it with a function
fComp = function(..., times, maxdif){
mb = microbenchmark(..., times=1)
if(max(abs(mb$time - lead(mb$time)), na.rm=TRUE)<maxdif) mb =
microbenchmark(..., times=times)
mb
}
mb = fComp(f1(100), f2(100), f3(100), times=10, maxdif = 1e6)
mb$time
# [1] 5988 29508 856 429 429 1 1 1 428 0 428 428 0
# [14] 428 1 1 428 0 1 0 1 429 1 1 0 428
# [27] 0 428 1 429
this is something weird going on.
My guess is that it's about passing the ... parameter. Unfortunately, I don't know how to properly decode ... to get the desired (as above) effect.
I will be grateful for any hint.