From 4492793e0ddc755b0db3a055fd9a2b9b215c656e Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Fri, 17 Feb 2023 11:46:19 -0800 Subject: [PATCH] Add a slightly-contrived tuple comparison benchmark --- library/core/benches/lib.rs | 1 + library/core/benches/tuple.rs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 library/core/benches/tuple.rs diff --git a/library/core/benches/lib.rs b/library/core/benches/lib.rs index e4100120d82..74ef0949b8a 100644 --- a/library/core/benches/lib.rs +++ b/library/core/benches/lib.rs @@ -20,6 +20,7 @@ mod pattern; mod slice; mod str; +mod tuple; /// Returns a `rand::Rng` seeded with a consistent seed. /// diff --git a/library/core/benches/tuple.rs b/library/core/benches/tuple.rs new file mode 100644 index 00000000000..d9ff9d0dd93 --- /dev/null +++ b/library/core/benches/tuple.rs @@ -0,0 +1,22 @@ +use rand::prelude::*; +use test::{black_box, Bencher}; + +#[bench] +fn bench_tuple_comparison(b: &mut Bencher) { + let mut rng = black_box(super::bench_rng()); + + let data = black_box([ + ("core::iter::adapters::Chain", 123_usize), + ("core::iter::adapters::Clone", 456_usize), + ("core::iter::adapters::Copie", 789_usize), + ("core::iter::adapters::Cycle", 123_usize), + ("core::iter::adapters::Flatt", 456_usize), + ("core::iter::adapters::TakeN", 789_usize), + ]); + + b.iter(|| { + let x = data.choose(&mut rng).unwrap(); + let y = data.choose(&mut rng).unwrap(); + [x < y, x <= y, x > y, x >= y] + }); +}