Skip to content

Commit

Permalink
Make sure not to give advantage to faster impls
Browse files Browse the repository at this point in the history
  • Loading branch information
Kijewski committed Aug 14, 2024
1 parent cf6bf01 commit 0529989
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ tinytemplate = { version = "*", optional = true, path = "tmpls/tinytemplate", pa

ahash = { version = "0.8.11", features = ["no-rng"] }
criterion = { version = "0.5.1", features = ["html_reports"] }
quanta = "0.12.3"

[[bench]]
name = "template-benchmark"
Expand Down
17 changes: 4 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::hint::black_box;
use std::time::Duration;
use std::time::{Duration, Instant};

use ahash::RandomState;
use criterion::{Bencher, Criterion};
use quanta::Instant;
use tmpls::{Benchmark, BigTable, Output, Team, Teams};

macro_rules! for_each {
Expand Down Expand Up @@ -91,20 +90,14 @@ fn run<B: Benchmark, I>(
func: impl Fn(&mut B, &mut B::Output, &I) -> Result<(), B::Error>,
) {
let mut output = B::Output::default();
for _ in 0..BATCH_SIZE {
func(this, &mut output, input).unwrap();
}
func(this, &mut output, input).unwrap();
let expected_hash = collect_output(&mut output);

b.iter_custom(|iters| {
let mut total = 0;
for _ in 0..iters.div_ceil(BATCH_SIZE as u64) {
for _ in 0..iters {
let start = Instant::now();
for _ in 0..BATCH_SIZE {
let output = black_box(&mut output);
let input = black_box(input);
func(this, output, input).unwrap();
}
black_box(func(this, black_box(&mut output), black_box(input))).unwrap();
total += start.elapsed().as_nanos() as u64;

let hash = collect_output(&mut output);
Expand All @@ -129,5 +122,3 @@ fn collect_output(output: &mut impl Output) -> u64 {
output.clear();
hash
}

const BATCH_SIZE: usize = 100;

0 comments on commit 0529989

Please sign in to comment.