Julia BenchmarkTools 输出

huangapple go评论60阅读模式
英文:

Julia BenchmarkTools output

问题

可以将BenchmarkTools(https://juliaci.github.io/BenchmarkTools.jl/stable/)生成的直方图保存到文件或绘制出来以供后续可视化吗?在交互式工作中,它似乎显示得很好,但在批处理模式下,我尚未找到保存这个输出直方图的选项。谢谢。

英文:

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.

答案1

得分: 2

你现在可以像任何 Julia 对象一样序列化 ben,使用 Serialization:

serialize("benchmark.ser", ben)

ben2 = deserialize("benchmark.ser")

有了这个对象,你可以随时显示它。

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 <

你可以将 ASCII 艺术保存到文件中:

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

这可以在支持完整 Unicode 集的任何文本编辑器或终端中显示。你还可以使用 readlines("bench.txt")

最后,数据也可以用于绘图:

using Plots

Plots.histogram(ben2.times)
英文:
julia&gt; ben = @benchmark cos.(rand(4));

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

serialize(&quot;benchmark.ser&quot;, ben)

ben2 = deserialize(&quot;benchmark.ser&quot;)

Having this object you could and display it any time.

julia&gt; 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 &#177; σ):   89.433 ns &#177;  39.911 ns  ┊ GC (mean &#177; σ):  2.05% &#177;  5.16%

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

You can save the ASCII art to a file:

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

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

Finally, the data is also available for plotting:

using Plots

Plots.histogram(ben2.times)

huangapple
  • 本文由 发表于 2023年2月6日 16:07:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75358739.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定