Skip to content

BTree: add benchmark of legacy ways to obtain first & last #86227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions library/alloc/benches/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ pub fn iteration_mut_100000(b: &mut Bencher) {
bench_iteration_mut(b, 100000);
}

fn bench_first_and_last(b: &mut Bencher, size: i32) {
fn bench_first_and_last_nightly(b: &mut Bencher, size: i32) {
let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
b.iter(|| {
for _ in 0..10 {
Expand All @@ -187,19 +187,44 @@ fn bench_first_and_last(b: &mut Bencher, size: i32) {
});
}

fn bench_first_and_last_stable(b: &mut Bencher, size: i32) {
let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
b.iter(|| {
for _ in 0..10 {
black_box(map.iter().next());
black_box(map.iter().next_back());
}
});
}

#[bench]
pub fn first_and_last_0_nightly(b: &mut Bencher) {
bench_first_and_last_nightly(b, 0);
}

#[bench]
pub fn first_and_last_0_stable(b: &mut Bencher) {
bench_first_and_last_stable(b, 0);
}

#[bench]
pub fn first_and_last_100_nightly(b: &mut Bencher) {
bench_first_and_last_nightly(b, 100);
}

#[bench]
pub fn first_and_last_0(b: &mut Bencher) {
bench_first_and_last(b, 0);
pub fn first_and_last_100_stable(b: &mut Bencher) {
bench_first_and_last_stable(b, 100);
}

#[bench]
pub fn first_and_last_100(b: &mut Bencher) {
bench_first_and_last(b, 100);
pub fn first_and_last_10k_nightly(b: &mut Bencher) {
bench_first_and_last_nightly(b, 10_000);
}

#[bench]
pub fn first_and_last_10k(b: &mut Bencher) {
bench_first_and_last(b, 10_000);
pub fn first_and_last_10k_stable(b: &mut Bencher) {
bench_first_and_last_stable(b, 10_000);
}

const BENCH_RANGE_SIZE: i32 = 145;
Expand Down