Huge overhaul of bytes

* Get rid of `ByteStr` trait
* `Bytes` is not a concrete type
* Add `BlockBuf`
* Delete lots of cruft
* Performance work
This commit is contained in:
Carl Lerche
2016-08-10 15:45:31 -07:00
parent b2efe63c70
commit 04e0ac75e2
31 changed files with 1630 additions and 1653 deletions
+27 -12
View File
@@ -1,34 +1,49 @@
#![feature(test, core)]
#![feature(test)]
use bytes::ByteBuf;
use bytes::traits::*;
use iobuf::{RWIobuf};
use bytes::alloc::Pool;
use test::Bencher;
use std::sync::Arc;
extern crate bytes;
extern crate iobuf;
extern crate test;
const SIZE:usize = 4_096;
#[bench]
pub fn bench_byte_buf_fill_4kb(b: &mut Bencher) {
pub fn bench_allocate_arc_vec(b: &mut Bencher) {
b.iter(|| {
let mut buf = ByteBuf::mut_with_capacity(SIZE);
let mut v = Vec::with_capacity(200);
for _ in 0..SIZE {
buf.write_slice(&[0]);
for _ in 0..200 {
let buf = Arc::new(Vec::<u8>::with_capacity(SIZE));
v.push(buf);
}
});
}
#[bench]
pub fn bench_rw_iobuf_fill_4kb(b: &mut Bencher) {
pub fn bench_allocate_byte_buf(b: &mut Bencher) {
b.iter(|| {
let mut buf = RWIobuf::new(SIZE);
let mut v = Vec::with_capacity(200);
for _ in 0..SIZE {
let _ = buf.fill(&[0]);
for _ in 0..200 {
let buf = ByteBuf::mut_with_capacity(SIZE);
v.push(buf);
}
});
}
#[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);
}
})
}