Skip to content

Commit

Permalink
Add VecDeque::extend TrustedLen benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobarbolini committed Jun 17, 2022
1 parent 0cb9899 commit ac2c21a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions library/alloc/benches/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,35 @@ fn bench_extend_vec(b: &mut Bencher) {
ring.extend(black_box(input));
});
}

#[bench]
fn bench_extend_trustedlen(b: &mut Bencher) {
let mut ring: VecDeque<u16> = VecDeque::with_capacity(1000);

b.iter(|| {
ring.clear();
ring.extend(black_box(0..512));
});
}

#[bench]
fn bench_extend_chained_trustedlen(b: &mut Bencher) {
let mut ring: VecDeque<u16> = VecDeque::with_capacity(1000);

b.iter(|| {
ring.clear();
ring.extend(black_box((0..256).chain(768..1024)));
});
}

#[bench]
fn bench_extend_chained_bytes(b: &mut Bencher) {
let mut ring: VecDeque<u16> = VecDeque::with_capacity(1000);
let input1: &[u16] = &[128; 256];
let input2: &[u16] = &[255; 256];

b.iter(|| {
ring.clear();
ring.extend(black_box(input1.iter().chain(input2.iter())));
});
}

0 comments on commit ac2c21a

Please sign in to comment.