From 5ac3ad61c42c9c97952a5df11d79e69ffcde73db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Sun, 9 Jun 2024 14:03:52 +0300 Subject: [PATCH] Extend functionality of tango benchmark helpers (#13107) # Description Refactors the tango helpers in the toolkit and makes them more flexible (e.g., being able to benchmark any branch against any branch, not just current and main). # User-Facing Changes # Tests + Formatting # After Submitting --- toolkit.nu | 78 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 17 deletions(-) diff --git a/toolkit.nu b/toolkit.nu index 6f19900fdb..0ef56d1077 100644 --- a/toolkit.nu +++ b/toolkit.nu @@ -491,29 +491,73 @@ export def cov [] { print $"Coverage generation took ($end - $start)." } - -# Benchmark the current branch against the main branch +# Benchmark a target revision (default: current branch) against a reference revision (default: main branch) +# +# Results are saved in a `./tango` directory # Ensure you have `cargo-export` installed to generate separate artifacts for each branch. -export def "benchmark-current-branch-with-main" [] { - let main = "main" - let current_branch = (git branch --show-current) +export def benchmark-compare [ + target?: string # which branch to compare (default: current branch) + reference?: string # the reference to compare against (default: main branch) +] { + let reference = $reference | default "main" + let current = git branch --show-current + let target = $target | default $current - cargo export $"target/($current_branch)" -- bench - git checkout $main - cargo export $"target/($main)" -- bench - git checkout $current_branch - ^$"./target/($current_branch)/benchmarks" compare $"./target/($main)/benchmarks" -o -s 50 + print $'-- Benchmarking ($target) against ($reference)' + + let export_dir = $env.PWD | path join "tango" + let ref_bin_dir = $export_dir | path join bin $reference + let tgt_bin_dir = $export_dir | path join bin $target + + # benchmark the target revision + print $'-- Running benchmarks for ($target)' + git checkout $target + cargo export $tgt_bin_dir -- bench + + # benchmark the comparison reference revision + print $'-- Running benchmarks for ($reference)' + git checkout $reference + cargo export $ref_bin_dir -- bench + + # return back to the whatever revision before benchmarking + print '-- Done' + git checkout $current + + # report results + let reference_bin = $ref_bin_dir | path join benchmarks + let target_bin = $tgt_bin_dir | path join benchmarks + ^$target_bin compare $reference_bin -o -s 50 --dump ($export_dir | path join samples) } -# Benchmark the current branch and logs the result in `./target/samples` +# Benchmark the current branch and logs the result in `./tango/samples` +# +# Results are saved in a `./tango` directory # Ensure you have `cargo-export` installed to generate separate artifacts for each branch. -export def "benchmark-and-log-result" [] { - let current_branch = (git branch --show-current) - let current_dir = "./" | path expand - let res_path = $"($current_dir)/target/samples" +export def benchmark-log [ + target?: string # which branch to compare (default: current branch) +] { + let current = git branch --show-current + let target = $target | default $current + print $'-- Benchmarking ($target)' - cargo export $"target/($current_branch)" -- bench - ^$"./target/($current_branch)/benchmarks" compare -o -s 50 --dump $res_path + let export_dir = $env.PWD | path join "tango" + let bin_dir = ($export_dir | path join bin $target) + + # benchmark the target revision + if $target != $current { + git checkout $target + } + cargo export $bin_dir -- bench + + # return back to the whatever revision before benchmarking + print '-- Done' + if $target != $current { + git checkout $current + } + + # report results + let bench_bin = ($bin_dir | path join benchmarks) + ^$bench_bin compare -o -s 50 --dump ($export_dir | path join samples) } # Build all Windows archives and MSIs for release manually