Skip to content

Commit

Permalink
Add a slightly-contrived tuple comparison benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmcm committed Feb 17, 2023
1 parent 680e216 commit 4492793
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions library/core/benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod ops;
mod pattern;
mod slice;
mod str;
mod tuple;

/// Returns a `rand::Rng` seeded with a consistent seed.
///
Expand Down
22 changes: 22 additions & 0 deletions library/core/benches/tuple.rs
Original file line number Diff line number Diff line change
@@ -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]
});
}

0 comments on commit 4492793

Please sign in to comment.