How do one use the list-argument in the microbenchmark
function.
I want to microbenchmark the same function with different inputs as in
microbenchmark(j1 = {sample(1e5)},
j2 = {sample(2e5)},
j3 = {sample(3e5)})
The following is not going to fly, as the list will just contain vectors and not unevaluated expressions.
microbenchmark(list = list(j1 = {sample(1e5)},
j2 = {sample(2e5)},
j3 = {sample(3e5)))
I would also want to generate the list using e.g. lapply
.
Just use alist
:
microbenchmark(list = alist(a = Sys.sleep(0.005), b = Sys.sleep(0.01)))
#> Unit: milliseconds
#> expr min lq mean median uq max neval cld
#> a 5.02905 5.15946 5.447538 5.446029 5.612429 6.030764 100 a
#> b 10.04997 10.18264 10.431011 10.459569 10.547814 11.058911 100 b
alist
handles its arguments as if they described function arguments. So the values are not evaluated, and tagged arguments with no value are allowed whereas list simply ignores them.
We need to use the substitute
or bquote
function to get the unevaluated expressions in the list, e.g.
microbenchmark(list = list(j1 = bquote({sample(1e5)}),
j2 = bquote({sample(2e5)}),
j3 = bquote({sample(3e5)})))
The jobs can be generated using lapply, but we have to be careful with environments
jobs = lapply(1000*1:3, function(s) local({s = s; bquote(sample(.(s)))}) )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With