This is a very simple question but I can’t find an easy answer. Any help appreciated!
I am trying to @benchmark the speed of a function over several orders-of-magnitude of inputs. I would like to just do a for-loop and then capture the benchmark output in a string (or, better, would be an object that I could query).
When I store the output of @benchmark in a variable x, though, I get some raw data that I’d rather not have to process. (Yes, in this case I can figure it out, but in general, sometimes I’d like to capture the screen summary output of a function in a string.)
Simple example code below. Any help welcome!!
Cheers, Nick
using BenchmarkTools # for @benchmark
using Statistics # for mean
function example_add(a,b)
c = a+b
end
x = @benchmark example_add(1, 2)
x
# Screen output -- how do I capture to a string or other variable?
#
# BenchmarkTools.Trial:
# memory estimate: 0 bytes
# allocs estimate: 0
# --------------
# minimum time: 0.025 ns (0.00% GC)
# median time: 0.029 ns (0.00% GC)
# mean time: 0.029 ns (0.00% GC)
# maximum time: 6.074 ns (0.00% GC)
# --------------
# samples: 10000
# evals/sample: 1000
minimum(x.times)
mean(x.times)
maximum(x.times)