Skip to content

Commit

Permalink
Properly align benchmark output
Browse files Browse the repository at this point in the history
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]]: bheisler/criterion.rs#704

Signed-off-by: Daniel Müller <[email protected]>
  • Loading branch information
d-e-s-o committed Jul 21, 2023
1 parent 2432820 commit ad211dc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
6 changes: 5 additions & 1 deletion benches/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
});
}
}
6 changes: 6 additions & 0 deletions benches/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:<width$}", width = BENCH_NAME_WIDTH)
}


fn benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("main");
Expand Down
9 changes: 6 additions & 3 deletions benches/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use blazesym::Addr;
use criterion::measurement::Measurement;
use criterion::BenchmarkGroup;

use crate::bench_fn_name;


/// Normalize addresses in the current process.
fn normalize_process() {
Expand All @@ -30,7 +32,8 @@ pub fn benchmark<M>(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),
);
}
13 changes: 8 additions & 5 deletions benches/symbolize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -78,14 +80,15 @@ pub fn benchmark<M>(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)
});
}
Expand Down

0 comments on commit ad211dc

Please sign in to comment.