From cf2419b1a9f04e89a63cc2ac2bc35a3b60ec8f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kijewski?= Date: Sat, 22 Jun 2024 15:54:58 +0200 Subject: [PATCH] derive: bench in batches Cloning a TokenStream is not for free. This change lets criterion do the cloning outside of the measured time, and blackboxing is done by criterion, too. The benchmark runs ~10% faster, now. --- rinja_derive_standalone/benches/derive-template.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rinja_derive_standalone/benches/derive-template.rs b/rinja_derive_standalone/benches/derive-template.rs index faf231ab..9b4bd210 100644 --- a/rinja_derive_standalone/benches/derive-template.rs +++ b/rinja_derive_standalone/benches/derive-template.rs @@ -1,4 +1,4 @@ -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; use quote::quote; criterion_main!(benches); @@ -19,7 +19,9 @@ fn hello_world(b: &mut criterion::Bencher<'_>) { user: &'a str, } }; - b.iter(|| { - rinja_derive_standalone::derive_template2(black_box(&ts).clone()); - }) + b.iter_batched( + || ts.clone(), + |ts| rinja_derive_standalone::derive_template2(ts), + BatchSize::LargeInput, + ); }