Skip to content

Commit 92fdfdf

Browse files
committed
Add ArrayVec::clone() benchmark
1 parent 0cb664c commit 92fdfdf

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ harness = false
4545
name = "arraystring"
4646
harness = false
4747

48+
[[bench]]
49+
name = "clone"
50+
harness = false
51+
4852
[features]
4953
default = ["std"]
5054
std = []

benches/clone.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
extern crate arrayvec;
3+
#[macro_use] extern crate bencher;
4+
5+
use arrayvec::ArrayVec;
6+
7+
use bencher::Bencher;
8+
use bencher::black_box;
9+
10+
fn clone_x<const N: usize>(b: &mut Bencher) {
11+
let mut v = ArrayVec::<u8, N>::new();
12+
v.extend((0..N).map(|x| x as u8));
13+
b.iter(|| {
14+
black_box(v.clone())
15+
});
16+
b.bytes = v.len() as u64;
17+
}
18+
19+
fn clone_8(b: &mut Bencher) {
20+
clone_x::<8>(b);
21+
}
22+
fn clone_16(b: &mut Bencher) {
23+
clone_x::<16>(b);
24+
}
25+
fn clone_32(b: &mut Bencher) {
26+
clone_x::<32>(b);
27+
}
28+
fn clone_64(b: &mut Bencher) {
29+
clone_x::<64>(b);
30+
}
31+
fn clone_512(b: &mut Bencher) {
32+
clone_x::<512>(b);
33+
}
34+
35+
benchmark_group!(benches,
36+
clone_8,
37+
clone_16,
38+
clone_32,
39+
clone_64,
40+
clone_512
41+
);
42+
43+
benchmark_main!(benches);

0 commit comments

Comments
 (0)