mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-16 00:00:15 +02:00
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:
+27
-12
@@ -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);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user