armando
armando

Reputation: 1480

Julia BenchmarkTools output

is it possible to save the histogram from BenchmarkTools (https://juliaci.github.io/BenchmarkTools.jl/stable/) into a file or plot for later visualization? It seems to display nicely when one works interactively but in batch mode, I haven't found an option to save this output histogram. Thanks.

Upvotes: 2

Views: 272

Answers (1)

Przemyslaw Szufel
Przemyslaw Szufel

Reputation: 42194

julia> ben = @benchmark cos.(rand(4));

you could now seriaze ben using Serialization - just like any Julia object:

serialize("benchmark.ser", ben)

ben2 = deserialize("benchmark.ser")

Having this object you could and display it any time.

julia> ben2
BenchmarkTools.Trial: 10000 samples with 968 evaluations.
 Range (min … max):  75.413 ns … 724.587 ns  ┊ GC (min … max): 0.00% … 80.84%
 Time  (median):     81.921 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   89.433 ns ±  39.911 ns  ┊ GC (mean ± σ):  2.05% ±  5.16%

  ▃▇█▆▄▃▁                                                      ▁
  ████████▇▆▆▅▄▅▅▇▇▆▆▅▆▅▄▅▄▄▅▃▆▄▃▅▆▄▅▄▅▅▄▆▅▄▄▄▄▄▅▆▆▆▆▅▅▄▅▄▃▃▂▃ █
  75.4 ns       Histogram: log(frequency) by time       244 ns <

You can save the ASCII art to a file:

open("bench.txt","w") do f
    show(f, "text/plain", ben)
end

This can be shown with any text editor or terminal that supports full Unicode set. You could also do readlines("bench.txt"),

Finally, the data is also available for plotting:

using Plots

Plots.histogram(ben2.times)

Upvotes: 2

Related Questions