Skip to content

Commit

Permalink
Add plot capability (#194)
Browse files Browse the repository at this point in the history
* Add plots recipes for single Trial or BenchmarkGroup of Trials

Co-authored-by: Valentin Churavy <vchuravy@users.noreply.github.com>
  • Loading branch information
gustaphe and vchuravy authored Jul 5, 2021
1 parent b7a51bd commit 51a918d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
11 changes: 11 additions & 0 deletions BenchmarkPlots/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name = "BenchmarkPlots"
uuid = "ab8c0f59-4072-4e0d-8f91-a91e1495eb26"
version = "0.1.0"

[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"

[compat]
BenchmarkTools = "1"
RecipesBase = "1"
25 changes: 25 additions & 0 deletions BenchmarkPlots/src/BenchmarkPlots.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module BenchmarkPlots
using RecipesBase
using BenchmarkTools: Trial, BenchmarkGroup

@recipe function f(::Type{Trial}, t::Trial)
seriestype --> :violin
legend --> false
yguide --> "t / ns"
xticks --> false
t.times
end

@recipe function f(g::BenchmarkGroup, keys=keys(g))
legend --> false
yguide --> "t / ns"
for k in keys
@series begin
label --> string(k)
xticks --> true
[string(k)], g[k]
end
end
end

end
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
julia = "1"
JSON = "0.18, 0.19, 0.20, 0.21"
JSON = "0.18, 0.19, 0.20, 0.21"

[extras]
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand Down
27 changes: 26 additions & 1 deletion docs/src/manual.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Manual

BenchmarkTools was created to facilitate the following tasks:

1. Organize collections of benchmarks into manageable benchmark suites
Expand Down Expand Up @@ -896,6 +895,32 @@ julia> loadparams!(suite, BenchmarkTools.load("params.json")[1], :evals, :sample

Caching parameters in this manner leads to a far shorter turnaround time, and more importantly, much more consistent results.

## Visualizing benchmark results
The `Trial` object can be visualized using the `BenchmarkPlots` package:

```julia
using BenchmarkPlots, StatsPlots
b = @benchmarkable lu(rand(10,10))
t = run(b)

plot(t)
```

This will show the timing results of the trial as a violin plot. You can use
all the keyword arguments from `Plots.jl`, for instance `st=:box` or
`yaxis=:log10`.

If a `BenchmarkGroup` contains (only) `Trial`s, its results can be visualized
simply by

```julia
using BenchmarkPlots, StatsPlots
t = run(g)
plot(t)
```

This will display each `Trial` as a violin plot.

## Miscellaneous tips and info

- BenchmarkTools restricts the minimum measurable benchmark execution time to one picosecond.
Expand Down

0 comments on commit 51a918d

Please sign in to comment.