Skip to content

Commit

Permalink
Add a benchmark for the insert case where index == len.
Browse files Browse the repository at this point in the history
  • Loading branch information
nnethercote authored and mbrubeck committed Jun 24, 2022
1 parent b233568 commit 7f9e513
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ make_benches! {
SmallVec<[u64; VEC_SIZE]> {
bench_push => gen_push(SPILLED_SIZE as _),
bench_push_small => gen_push(VEC_SIZE as _),
bench_insert_push => gen_insert_push(SPILLED_SIZE as _),
bench_insert_push_small => gen_insert_push(VEC_SIZE as _),
bench_insert => gen_insert(SPILLED_SIZE as _),
bench_insert_small => gen_insert(VEC_SIZE as _),
bench_remove => gen_remove(SPILLED_SIZE as _),
Expand All @@ -118,6 +120,8 @@ make_benches! {
Vec<u64> {
bench_push_vec => gen_push(SPILLED_SIZE as _),
bench_push_vec_small => gen_push(VEC_SIZE as _),
bench_insert_push_vec => gen_insert_push(SPILLED_SIZE as _),
bench_insert_push_vec_small => gen_insert_push(VEC_SIZE as _),
bench_insert_vec => gen_insert(SPILLED_SIZE as _),
bench_insert_vec_small => gen_insert(VEC_SIZE as _),
bench_remove_vec => gen_remove(SPILLED_SIZE as _),
Expand Down Expand Up @@ -151,6 +155,21 @@ fn gen_push<V: Vector<u64>>(n: u64, b: &mut Bencher) {
});
}

fn gen_insert_push<V: Vector<u64>>(n: u64, b: &mut Bencher) {
#[inline(never)]
fn insert_push_noinline<V: Vector<u64>>(vec: &mut V, x: u64) {
vec.insert(x as usize, x);
}

b.iter(|| {
let mut vec = V::new();
for x in 0..n {
insert_push_noinline(&mut vec, x);
}
vec
});
}

fn gen_insert<V: Vector<u64>>(n: u64, b: &mut Bencher) {
#[inline(never)]
fn insert_noinline<V: Vector<u64>>(vec: &mut V, p: usize, x: u64) {
Expand Down

0 comments on commit 7f9e513

Please sign in to comment.