Skip to content

Commit 4492793

Browse files
committed
Add a slightly-contrived tuple comparison benchmark
1 parent 680e216 commit 4492793

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

library/core/benches/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ mod ops;
2020
mod pattern;
2121
mod slice;
2222
mod str;
23+
mod tuple;
2324

2425
/// Returns a `rand::Rng` seeded with a consistent seed.
2526
///

library/core/benches/tuple.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use rand::prelude::*;
2+
use test::{black_box, Bencher};
3+
4+
#[bench]
5+
fn bench_tuple_comparison(b: &mut Bencher) {
6+
let mut rng = black_box(super::bench_rng());
7+
8+
let data = black_box([
9+
("core::iter::adapters::Chain", 123_usize),
10+
("core::iter::adapters::Clone", 456_usize),
11+
("core::iter::adapters::Copie", 789_usize),
12+
("core::iter::adapters::Cycle", 123_usize),
13+
("core::iter::adapters::Flatt", 456_usize),
14+
("core::iter::adapters::TakeN", 789_usize),
15+
]);
16+
17+
b.iter(|| {
18+
let x = data.choose(&mut rng).unwrap();
19+
let y = data.choose(&mut rng).unwrap();
20+
[x < y, x <= y, x > y, x >= y]
21+
});
22+
}

0 commit comments

Comments
 (0)