英文:
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> 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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论