Skip to content

Commit 5ae217a

Browse files
authored
Include the cost of shifts in insert/remove benchmarks (#268)
Thanks!
1 parent 58edc0e commit 5ae217a

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

benches/bench.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,11 @@ fn gen_insert<V: Vector<u64>>(n: u64, b: &mut Bencher) {
159159

160160
b.iter(|| {
161161
let mut vec = V::new();
162-
// Add one element, with each iteration we insert one before the end.
163-
// This means that we benchmark the insertion operation and not the
164-
// time it takes to `ptr::copy` the data.
162+
// Always insert at position 0 so that we are subject to shifts of
163+
// many different lengths.
165164
vec.push(0);
166165
for x in 0..n {
167-
insert_noinline(&mut vec, x as _, x);
166+
insert_noinline(&mut vec, 0, x);
168167
}
169168
vec
170169
});
@@ -179,8 +178,8 @@ fn gen_remove<V: Vector<u64>>(n: usize, b: &mut Bencher) {
179178
b.iter(|| {
180179
let mut vec = V::from_elem(0, n as _);
181180

182-
for x in (0..n - 1).rev() {
183-
remove_noinline(&mut vec, x);
181+
for _ in 0..n {
182+
remove_noinline(&mut vec, 0);
184183
}
185184
});
186185
}

0 commit comments

Comments
 (0)