Skip to content

Commit a7c4bcd

Browse files
art049claude
andcommitted
chore: remove unnecessary black_box in divan and bencher compat layers
Apply the same optimization from PR 98 to both divan and bencher compat layers: - Remove black_box around routine calls during measurement - Only apply black_box to outputs after measurement ends - Reduces stack usage and eliminates unnecessary memory operations - Improves benchmark performance by avoiding artificial overhead 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fc76872 commit a7c4bcd

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

crates/bencher_compat/src/compat.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ impl Bencher {
3838
black_box(inner());
3939
}
4040
self.codspeed.start_benchmark(uri.as_str());
41-
black_box(inner());
41+
let output = inner();
4242
self.codspeed.end_benchmark();
43+
black_box(output);
4344
}
4445
}
4546

crates/divan_compat/src/compat/bench/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ where
9797
let mut gen_input = self.config.gen_input.borrow_mut();
9898
let input = gen_input();
9999
codspeed.start_benchmark(self.uri.as_str());
100-
divan::black_box(benched(input));
100+
let output = benched(input);
101101
codspeed.end_benchmark();
102+
divan::black_box(output);
102103
}
103104

104105
pub fn bench_local_refs<O, B>(self, mut benched: B)
@@ -110,7 +111,8 @@ where
110111
let mut input = gen_input();
111112

112113
codspeed.start_benchmark(self.uri.as_str());
113-
divan::black_box(benched(&mut input));
114+
let output = benched(&mut input);
114115
codspeed.end_benchmark();
116+
divan::black_box(output);
115117
}
116118
}

0 commit comments

Comments
 (0)