2016-08-10 15:45:31 -07:00
|
|
|
#![feature(test)]
|
2015-02-09 22:20:55 -08:00
|
|
|
|
|
|
|
|
use bytes::ByteBuf;
|
2016-08-10 15:45:31 -07:00
|
|
|
use bytes::alloc::Pool;
|
2015-02-09 22:20:55 -08:00
|
|
|
use test::Bencher;
|
2016-08-10 15:45:31 -07:00
|
|
|
use std::sync::Arc;
|
2015-02-09 22:20:55 -08:00
|
|
|
|
|
|
|
|
extern crate bytes;
|
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
|
|
const SIZE:usize = 4_096;
|
|
|
|
|
|
|
|
|
|
#[bench]
|
2016-08-10 15:45:31 -07:00
|
|
|
pub fn bench_allocate_arc_vec(b: &mut Bencher) {
|
2015-02-09 22:20:55 -08:00
|
|
|
b.iter(|| {
|
2016-08-10 15:45:31 -07:00
|
|
|
let mut v = Vec::with_capacity(200);
|
2015-02-09 22:20:55 -08:00
|
|
|
|
2016-08-10 15:45:31 -07:00
|
|
|
for _ in 0..200 {
|
|
|
|
|
let buf = Arc::new(Vec::<u8>::with_capacity(SIZE));
|
|
|
|
|
v.push(buf);
|
2015-02-09 22:20:55 -08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[bench]
|
2016-08-10 15:45:31 -07:00
|
|
|
pub fn bench_allocate_byte_buf(b: &mut Bencher) {
|
2015-02-09 22:20:55 -08:00
|
|
|
b.iter(|| {
|
2016-08-10 15:45:31 -07:00
|
|
|
let mut v = Vec::with_capacity(200);
|
2015-02-09 22:20:55 -08:00
|
|
|
|
2016-08-10 15:45:31 -07:00
|
|
|
for _ in 0..200 {
|
|
|
|
|
let buf = ByteBuf::mut_with_capacity(SIZE);
|
|
|
|
|
v.push(buf);
|
2015-02-09 22:20:55 -08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-08-10 15:45:31 -07:00
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
|
pub fn bench_allocate_with_pool(b: &mut Bencher) {
|
|
|
|
|
let mut pool = Pool::with_capacity(1_024, SIZE);
|
|
|
|
|
|
|
|
|
|
b.iter(|| {
|
|
|
|
|
let mut v = Vec::with_capacity(200);
|
|
|
|
|
|
|
|
|
|
for _ in 0..200 {
|
|
|
|
|
let buf = pool.new_byte_buf();
|
|
|
|
|
v.push(buf);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|