BenchmarkTools @benchmark beautiful histogram reuse

Dear Julianners,

I saw the beautiful histogram unicode plots of BenchmarkTools of @benchmark

 10000 samples with 968 evaulations took a median time of 90.902 ns (0.00% GC)
 Time  (mean ± σ):   94.936 ns ±  47.797 ns  (GC: 2.78% ±  5.03%)
 Range (min … max):  77.655 ns … 954.823 ns  (GC: 0.00% … 87.94%)

  77.7 ns         Histogram: frequency by time           137 ns

How can I use their histogram plotting?


Could you clarify your question? What do you mean by “use their histogram”?

Yes, or modify it a little.
I mean by using it, to do histogram plotting with their UI using my dataset, to be precise.

So you want to plot a histogram of your own data (just any data, not benchmarking results) using the histogram from BenchmarkTools?

The relevant code is here:

Although I probably would just use UnicodePlots to create plots in the terminal (either standalone or as a Plots backend):

julia> using UnicodePlots

julia> histogram(randn(10_000), xlabel = "Something", ylabel = "Something else")
                               ┌                                        ┐ 
                  [-5.0, -4.0) ┤▏ 1                                       
                  [-4.0, -3.0) ┤▎ 19                                      
                  [-3.0, -2.0) ┤██▎ 217                                   
                  [-2.0, -1.0) ┤█████████████▎ 1342                       
   Something else [-1.0,  0.0) ┤██████████████████████████████████  3454  
                  [ 0.0,  1.0) ┤█████████████████████████████████▏ 3359   
                  [ 1.0,  2.0) ┤█████████████▋ 1385                       
                  [ 2.0,  3.0) ┤██▎ 212                                   
                  [ 3.0,  4.0) ┤▎ 10                                      
                  [ 4.0,  5.0) ┤▏ 1                                       
                               └                                        ┘ 

Sorry, the key is to produce similar output. I think I forgot to mention that.
So basically I need the a vertical histogram that is used by BenchmarkTools.

Ok I think I see.

I think I will copy this.


I had to modify it a little bit so I created a vertical unicode histogram plot again

I hope it is useful for the community by time…

1 Like

why not add this vertical unicode histogram plot to UnicodePlots.jl ?


How to add it to a repository like that?

You’d open an issue in the UnicodePlots repo, and then point them to your implementation.
Then you can iterate with the authors of UnicodePlots on how to best integrate your code into the existing repo.


Btw, I’ve also just looked for a way to make a vertical hist in UnicodePlots. Thanks for making your code available!
You could also think about just plotting the outline.
Maybe it depends on the terminal whether or not this is easy to see…

If you are willing, you can contribute to the PR opened by @Marcell_Havlik at vertical histogram base by Cvikli · Pull Request #221 · JuliaPlots/UnicodePlots.jl · GitHub, since it will need more rework before integration.

I just wanted to note if someone wants to take the effort to merge this repo UnicodePlotsSimple.jl into the main JuliaPlots/UnicodePlots.jl
Pull Request #221 - JuliaPlots/UnicodePlots.jl GitHub

1 Like