FEAT: Add benchmarks for .extend()

This commit is contained in:
bluss
2017-10-08 17:27:24 +02:00
parent d89699ff63
commit af8b746fc4
2 changed files with 48 additions and 0 deletions
+5
View File
@@ -30,6 +30,11 @@ version = "1.0"
[dev-dependencies] [dev-dependencies]
matches = { version = "0.1" } matches = { version = "0.1" }
bencher = "0.1.4"
[[bench]]
name = "extend"
harness = false
[features] [features]
default = ["std"] default = ["std"]
+43
View File
@@ -0,0 +1,43 @@
extern crate arrayvec;
#[macro_use] extern crate bencher;
use arrayvec::ArrayVec;
use bencher::Bencher;
fn extend_with_constant(b: &mut Bencher) {
let mut v = ArrayVec::<[u8; 512]>::new();
let cap = v.capacity();
b.iter(|| {
v.clear();
v.extend((0..cap).map(|_| 1));
v[0]
});
b.bytes = v.capacity() as u64;
}
fn extend_with_range(b: &mut Bencher) {
let mut v = ArrayVec::<[u8; 512]>::new();
let cap = v.capacity();
b.iter(|| {
v.clear();
v.extend((0..cap).map(|x| x as _));
v[0]
});
b.bytes = v.capacity() as u64;
}
fn extend_with_slice(b: &mut Bencher) {
let mut v = ArrayVec::<[u8; 512]>::new();
let data = [1; 512];
b.iter(|| {
v.clear();
v.extend(data.iter().cloned());
v[0]
});
b.bytes = v.capacity() as u64;
}
benchmark_group!(benches, extend_with_constant, extend_with_range, extend_with_slice);
benchmark_main!(benches);