Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Manifest.toml

# Test data files and benchmarking
jetsavetest*.dat
benchmark/*
tune.json

# Misc files
.DS_Store
Expand Down
8 changes: 8 additions & 0 deletions benchmark/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
JetReconstruction = "44e8cb2c-dfab-4825-9c70-d4808a591196"
PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d"

[sources]
JetReconstruction = {path = ".."}
19 changes: 19 additions & 0 deletions benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Mini-benchmarks for JetReconstruction

This directory contains mini-benchmarks for the `JetReconstruction.jl` package. A more comprehensive suite of benchmarks can be found in [JetReconstructionBenchmarks.jl](https://github.com/graeme-a-stewart/JetReconstructionBenchmarks.jl).

## PkgBenchmark-style benchmarks

The [benchmark/benchmarks.jl](benchmark/benchmarks.jl) benchmarks follow the standard [`PkgBenchmark.jl`](https://juliaci.github.io/PkgBenchmark.jl/stable/) structure and can be run locally with your favourite `PkgBenchmark.jl`-compatible tool, for example:

```julia
using PkgBenchmark
import JetReconstruction
benchmarkpkg(JetReconstruction)
```

Alternatively, the benchmarks can be run directly from the command line with:

```sh
julia --project=benchmark benchmark/runbenchmarks.jl --verbose benchmark_results.json
```
59 changes: 59 additions & 0 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Benchmark suite for JetReconstruction.jl compatible with PkgBenchmark.jl."""

using BenchmarkTools
using JetReconstruction

const events_file_pp = joinpath(@__DIR__, "..", "test", "data", "events.pp13TeV.hepmc3.zst")
const events_file_ee = joinpath(@__DIR__, "..", "test", "data", "events.eeH.hepmc3.zst")

const pp_events = JetReconstruction.read_final_state_particles(events_file_pp, PseudoJet)
const ee_events = JetReconstruction.read_final_state_particles(events_file_ee, EEJet)

function jet_reconstruct_harness(events; algorithm, strategy, distance, power = nothing,
recombine = RecombinationMethods[RecombinationScheme.EScheme],
ptmin::Real = 5.0, dcut = nothing, njets = nothing,)
for event in events
cs = jet_reconstruct(event; R = distance, p = power, algorithm = algorithm,
strategy = strategy, recombine...)
if !isnothing(njets)
finaljets = exclusive_jets(cs; njets = njets)
elseif !isnothing(dcut)
finaljets = exclusive_jets(cs; dcut = dcut)
else
finaljets = inclusive_jets(cs; ptmin = ptmin)
end
end
end

const SUITE = BenchmarkGroup()

## pp events
let pp_group = SUITE["pp"] = BenchmarkGroup(["pp"])
for stg in [RecoStrategy.N2Plain, RecoStrategy.N2Tiled]
strategy_group = pp_group["$stg"] = BenchmarkGroup(["$stg"])
for alg in [JetAlgorithm.AntiKt, JetAlgorithm.CA, JetAlgorithm.Kt]
alg_group = strategy_group["$alg"] = BenchmarkGroup(["$alg"])
for distance in [0.4, 1.0, 1.5]
alg_group["$distance"] = @benchmarkable jet_reconstruct_harness($pp_events;
algorithm = $alg,
strategy = $stg,
distance = $distance,
ptmin = 5.0) evals=1 samples=32
end
end
end
end

## ee events
let ee_group = SUITE["ee"] = BenchmarkGroup(["ee"])
for alg in [JetAlgorithm.Durham]
alg_group = SUITE["ee"]["$alg"] = BenchmarkGroup(["$alg"])
for distance in [0.4, 1.0, 1.5]
alg_group["$distance"] = @benchmarkable jet_reconstruct_harness($ee_events;
algorithm = $alg,
strategy = $RecoStrategy.Best,
distance = $distance,
ptmin = 5.0) evals=1 samples=32
end
end
end
59 changes: 59 additions & 0 deletions benchmark/runbenchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Benchmark runner for JetReconstruction.jl package."""

using ArgParse
using BenchmarkTools
using PkgBenchmark

"""
find_trials(group::BenchmarkGroup; path=[])

Recursively traverse a BenchmarkGroup and return a flat dictionary of all BenchmarkTools.Trial objects found
with their hierarchical path as the key.
"""
function find_trials(group::BenchmarkGroup; path = [])
leaves = Dict{String, BenchmarkTools.Trial}()

for (k, v) in group
newpath = [path..., string(k)]
if v isa BenchmarkGroup
merge!(leaves, find_trials(v; path = newpath))
elseif v isa BenchmarkTools.Trial
key = join(newpath, "/")
leaves[key] = v
end
end

return leaves
end

function display_results(flat_results::Dict)
for (key, trial) in flat_results
println("• $key")
display(trial)
end
end

function parse_command_line(args)
s = ArgParseSettings(autofix_names = true,
description = "Run JetReconstruction.jl benchmark suite")
@add_arg_table! s begin
"--verbose", "-v"
help = "Enable verbose output, print results to console"
action = :store_true

"output"
help = "Write benchmark results to BenchmarkTools.BenchmarkGroup JSON formatted file"
end
return parse_args(args, s)
end

function (@main)(args)
parsed_args = parse_command_line(args)
results = benchmarkpkg(dirname(@__DIR__); resultfile = parsed_args["output"])
if parsed_args["verbose"]
(display_results ∘ find_trials ∘ PkgBenchmark.benchmarkgroup)(results)
end
return 0
end

@isdefined(var"@main") ? (@main) : exit(main(ARGS))
Loading