From ad211dcf9306af1b2c6a29e276c3b3d6b633aaa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Fri, 21 Jul 2023 15:22:20 -0700 Subject: [PATCH] Properly align benchmark output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unfortunately criterion with the bencher output format does not align benchmark results properly ([[0]]). As a result it is quite hard to read the summary from a glimpse. To work around this problem, this change "manually" adjusts the names of our benchmark functions so that the corresponding results in the summary report are aligned properly. [[0]]: https://github.com/bheisler/criterion.rs/issues/704 Signed-off-by: Daniel Müller --- benches/inspect.rs | 6 +++++- benches/main.rs | 6 ++++++ benches/normalize.rs | 9 ++++++--- benches/symbolize.rs | 13 ++++++++----- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/benches/inspect.rs b/benches/inspect.rs index 7450cad7d..4e64d8723 100644 --- a/benches/inspect.rs +++ b/benches/inspect.rs @@ -7,6 +7,8 @@ use blazesym::inspect::Inspector; use criterion::measurement::Measurement; use criterion::BenchmarkGroup; +use crate::bench_fn_name; + /// Lookup an address in a DWARF file, end-to-end, i.e., including all necessary /// setup. @@ -34,6 +36,8 @@ where M: Measurement, { if cfg!(feature = "generate-large-test-files") { - group.bench_function(stringify!(inspect::lookup_dwarf), |b| b.iter(lookup_dwarf)); + group.bench_function(bench_fn_name(stringify!(inspect::lookup_dwarf)), |b| { + b.iter(lookup_dwarf) + }); } } diff --git a/benches/main.rs b/benches/main.rs index 6de10e287..6340aa32c 100644 --- a/benches/main.rs +++ b/benches/main.rs @@ -10,6 +10,12 @@ use criterion::criterion_group; use criterion::criterion_main; use criterion::Criterion; +const BENCH_NAME_WIDTH: usize = 42; + +pub(crate) fn bench_fn_name(name: &str) -> String { + format!("{name:(group: &mut BenchmarkGroup<'_, M>) where M: Measurement, { - group.bench_function(stringify!(normalize::normalize_process), |b| { - b.iter(normalize_process) - }); + group.bench_function( + bench_fn_name(stringify!(normalize::normalize_process)), + |b| b.iter(normalize_process), + ); } diff --git a/benches/symbolize.rs b/benches/symbolize.rs index 0f812b473..7b0d7a8c3 100644 --- a/benches/symbolize.rs +++ b/benches/symbolize.rs @@ -13,6 +13,8 @@ use blazesym::Pid; use criterion::measurement::Measurement; use criterion::BenchmarkGroup; +use crate::bench_fn_name; + /// Symbolize addresses in the current process. fn symbolize_process() { @@ -78,14 +80,15 @@ pub fn benchmark(group: &mut BenchmarkGroup<'_, M>) where M: Measurement, { - group.bench_function(stringify!(symbolize::symbolize_process), |b| { - b.iter(symbolize_process) - }); + group.bench_function( + bench_fn_name(stringify!(symbolize::symbolize_process)), + |b| b.iter(symbolize_process), + ); if cfg!(feature = "generate-large-test-files") { - group.bench_function(stringify!(symbolize::symbolize_dwarf), |b| { + group.bench_function(bench_fn_name(stringify!(symbolize::symbolize_dwarf)), |b| { b.iter(symbolize_dwarf) }); - group.bench_function(stringify!(symbolize::symbolize_gsym), |b| { + group.bench_function(bench_fn_name(stringify!(symbolize::symbolize_gsym)), |b| { b.iter(symbolize_gsym) }); }