From 9366daa09d2609fbfdfc8b859d99dec1f0107650 Mon Sep 17 00:00:00 2001 From: AngelicosPhosphoros Date: Tue, 8 Oct 2024 21:53:00 +0200 Subject: [PATCH] Use `black_box` when running benchmarks to avoid compiler microoptimizations --- benches/overhead.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/benches/overhead.rs b/benches/overhead.rs index 710ad6d..616064b 100644 --- a/benches/overhead.rs +++ b/benches/overhead.rs @@ -1,3 +1,5 @@ +use std::hint::black_box; + use chili::Scope; use divan::Bencher; @@ -49,7 +51,7 @@ fn no_overhead(bencher: Bencher, nodes: (usize, usize)) { let mut scope = Scope::global(); bencher.bench_local(move || { - assert_eq!(sum(&tree, &mut scope), nodes.1 as u64); + assert_eq!(sum(black_box(&tree), &mut scope), nodes.1 as u64); }); } @@ -68,7 +70,7 @@ fn chili_overhead(bencher: Bencher, nodes: (usize, usize)) { let mut scope = Scope::global(); bencher.bench_local(move || { - assert_eq!(sum(&tree, &mut scope), nodes.1 as u64); + assert_eq!(sum(black_box(&tree), &mut scope), nodes.1 as u64); }); } @@ -86,7 +88,7 @@ fn rayon_overhead(bencher: Bencher, nodes: (usize, usize)) { let tree = Node::tree(nodes.0); bencher.bench_local(move || { - assert_eq!(sum(&tree), nodes.1 as u64); + assert_eq!(sum(black_box(&tree)), nodes.1 as u64); }); }