hyperfine icon indicating copy to clipboard operation
hyperfine copied to clipboard

Benchmark across different branches

Open technicalpickles opened this issue 2 years ago • 2 comments
trafficstars

When I'm working on performance, I tend to want to compare a baseline from our main branch against my current work. It'd be pretty handy to be able to specify branches at the CLI level to handle the switch. Maybe:

hyperfine --compare-branch main "rails runner true"

You can achieve something similar by including the git checkouts in the command:

$ hyperfine "git switch main; DISABLE_SPRING=1 bin/rails runner true" "git switch performance-improvements; DISABLE_SPRING=1 bin/rails runner true"
Benchmark 1: git checkout main; DISABLE_SPRING=1 bin/rails runner true
  Time (mean ± σ):      8.690 s ±  0.876 s    [User: 4.835 s, System: 4.665 s]
  Range (min … max):    8.114 s … 11.106 s    10 runs

Benchmark 2: git switch performance-improvements; DISABLE_SPRING=1 bin/rails runner true
  Time (mean ± σ):      8.352 s ±  0.363 s    [User: 4.778 s, System: 4.621 s]
  Range (min … max):    7.950 s …  9.020 s    10 runs

Summary
  'git switch performance-improvements; DISABLE_SPRING=1 bin/rails runner true' ran
    1.04 ± 0.11 times faster than 'git checkout main; DISABLE_SPRING=1 bin/rails runner true'

technicalpickles avatar Jan 25 '23 17:01 technicalpickles

You can do this using a combination of --parameter-list and --setup. Something like the following should work:

hyperfine \
  --parameter-list branch main,performance-improvements \
  --setup "git switch {branch}" \
  "rails runner true"

When I'm working on performance, I tend to want to compare a baseline from our main branch against my current work.

This is indeed a very common use case. We should probably write some documentation for that.

sharkdp avatar Feb 28 '23 21:02 sharkdp

Another way to do this is to use git worktree to have both main/master branch and your work branch checked out and built and run the benchmark with both. This way you can run benchmarks with uncommitted changes.

nirs avatar Jun 03 '23 12:06 nirs