Created
November 24, 2014 14:05
-
-
Save japaric/e383ef056f5b9c8f2513 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "serial" | |
version = "0.0.1" | |
authors = ["Jorge Aparicio <[email protected]>"] | |
[dependencies.criterion] | |
git = "https://github.com/japaric/criterion.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(slicing_syntax)] | |
extern crate criterion; | |
use criterion::Criterion; | |
use std::cmp::min; | |
use std::io::{IoError, IoResult}; | |
use std::raw::Repr; | |
use std::{io, mem, ptr, raw, slice}; | |
const SRC_LEN: uint = 4; | |
const BATCHES: uint = 128; | |
fn main() { | |
Criterion::default(). | |
bench("writer/std_vec_writer", |b| { | |
let mut dst = Vec::with_capacity(BATCHES * SRC_LEN); | |
let src = &[1, .. SRC_LEN]; | |
b.iter(|| { | |
dst.clear(); | |
do_std_writes_inline_never(&mut dst, src, BATCHES); | |
}) | |
}). | |
bench("writer/std_buf_writer", |b| { | |
let dst = &mut [0, .. BATCHES * SRC_LEN]; | |
let src = &[1, .. SRC_LEN]; | |
b.iter(|| { | |
let mut dst = io::BufWriter::new(dst); | |
do_std_writes_inline_never(&mut dst, src, BATCHES); | |
}) | |
}). | |
bench("writer/copy_nonoverlapping", |b| { | |
let dst = &mut [0_u8, .. BATCHES * SRC_LEN]; | |
let src = &[1, .. SRC_LEN]; | |
b.iter(|| { | |
unsafe { | |
do_copy_nonoverlapping_memory_inline_never(dst.as_mut_ptr(), src.as_ptr(), src.len(), BATCHES); | |
} | |
}) | |
}). | |
bench("writer/slice_writer", |b| { | |
let dst = &mut [0, .. BATCHES * SRC_LEN]; | |
let src = &[1, .. SRC_LEN]; | |
b.iter(|| { | |
let mut dst = dst.as_mut_slice(); | |
do_my_writes_inline_never(&mut dst, src, BATCHES); | |
}) | |
}). | |
bench("writer/unsafe_writer", |b| { | |
let dst = &mut [0, .. BATCHES * SRC_LEN]; | |
let src = &[1, .. SRC_LEN]; | |
b.iter(|| { | |
let mut dst = UnsafeWriter::new(dst); | |
do_my_writes_inline_never(&mut dst, src, BATCHES); | |
}) | |
}). | |
bench("writer/buf_writer_0", |b| { | |
let dst = &mut [0, .. BATCHES * SRC_LEN]; | |
let src = &[1, .. SRC_LEN]; | |
b.iter(|| { | |
let mut dst = BufWriter0::new(dst); | |
do_my_writes_inline_never(&mut dst, src, BATCHES); | |
}) | |
}). | |
bench("writer/buf_writer_1", |b| { | |
let dst = &mut [0, .. BATCHES * SRC_LEN]; | |
let src = &[1, .. SRC_LEN]; | |
b.iter(|| { | |
let mut dst = BufWriter1::new(dst); | |
do_my_writes_inline_never(&mut dst, src, BATCHES); | |
}) | |
}). | |
bench("writer/buf_writer_2", |b| { | |
let dst = &mut [0, .. BATCHES * SRC_LEN]; | |
let src = &[1, .. SRC_LEN]; | |
b.iter(|| { | |
let mut dst = BufWriter2::new(dst); | |
do_my_writes_inline_never(&mut dst, src, BATCHES); | |
}) | |
}). | |
bench("writer/buf_writer_3", |b| { | |
let dst = &mut [0, .. BATCHES * SRC_LEN]; | |
let src = &[1, .. SRC_LEN]; | |
b.iter(|| { | |
let mut dst = BufWriter3::new(dst); | |
do_my_writes_inline_never(&mut dst, src, BATCHES); | |
}) | |
}). | |
bench("writer/buf_writer_4", |b| { | |
let dst = &mut [0, .. BATCHES * SRC_LEN]; | |
let src = &[1, .. SRC_LEN]; | |
b.iter(|| { | |
let mut dst = BufWriter4::new(dst); | |
do_my_writes_inline_never(&mut dst, src, BATCHES); | |
}) | |
}). | |
bench("writer/buf_writer_5", |b| { | |
let dst = &mut [0, .. BATCHES * SRC_LEN]; | |
let src = &[1, .. SRC_LEN]; | |
b.iter(|| { | |
let mut dst = BufWriter5::new(dst); | |
do_my_writes_inline_never(&mut dst, src, BATCHES); | |
}) | |
}). | |
bench("writer/buf_writer_6", |b| { | |
let dst = &mut [0, .. BATCHES * SRC_LEN]; | |
let src = &[1, .. SRC_LEN]; | |
b.iter(|| { | |
let mut dst = BufWriter6::new(dst); | |
do_my_writes_inline_never(&mut dst, src, BATCHES); | |
}) | |
}). | |
bench("writer/buf_writer_7", |b| { | |
let dst = &mut [0, .. BATCHES * SRC_LEN]; | |
let src = &[1, .. SRC_LEN]; | |
b.iter(|| { | |
let mut dst = BufWriter7::new(dst); | |
do_my_writes_inline_never(&mut dst, src, BATCHES); | |
}) | |
}). | |
bench("writer/buf_writer_8", |b| { | |
let dst = &mut [0, .. BATCHES * SRC_LEN]; | |
let src = &[1, .. SRC_LEN]; | |
b.iter(|| { | |
let mut dst = BufWriter8::new(dst); | |
do_my_writes_inline_never(&mut dst, src, BATCHES); | |
}) | |
}). | |
bench("writer/buf_writer_9", |b| { | |
let dst = &mut [0, .. BATCHES * SRC_LEN]; | |
let src = &[1, .. SRC_LEN]; | |
b.iter(|| { | |
let mut dst = BufWriter9::new(dst); | |
do_my_writes_inline_never(&mut dst, src, BATCHES); | |
}) | |
}). | |
bench("writer/buf_writer_10", |b| { | |
let dst = &mut [0, .. BATCHES * SRC_LEN]; | |
let src = &[1, .. SRC_LEN]; | |
b.iter(|| { | |
let mut dst = BufWriter10::new(dst); | |
do_my_writes_inline_never(&mut dst, src, BATCHES); | |
}) | |
}). | |
bench("writer/buf_writer_11", |b| { | |
let dst = &mut [0, .. BATCHES * SRC_LEN]; | |
let src = &[1, .. SRC_LEN]; | |
b.iter(|| { | |
let mut dst = BufWriter11::new(dst); | |
do_my_writes_inline_never(&mut dst, src, BATCHES); | |
}) | |
}). | |
bench("writer/buf_writer_12", |b| { | |
let dst = &mut [0, .. BATCHES * SRC_LEN]; | |
let src = &[1, .. SRC_LEN]; | |
b.iter(|| { | |
let mut dst = BufWriter12::new(dst); | |
do_my_writes_inline_never(&mut dst, src, BATCHES); | |
}) | |
}). | |
bench("writer/buf_writer_13", |b| { | |
let dst = &mut [0, .. BATCHES * SRC_LEN]; | |
let src = &[1, .. SRC_LEN]; | |
b.iter(|| { | |
let mut dst = BufWriter13::new(dst); | |
do_my_writes_inline_never(&mut dst, src, BATCHES); | |
}) | |
}). | |
bench("writer/vec_writer_1", |b| { | |
let mut dst = Vec::with_capacity(BATCHES * SRC_LEN); | |
let src = &[1, .. SRC_LEN]; | |
b.iter(|| { | |
dst.clear(); | |
let mut dst = VecWriter1::new(&mut dst); | |
do_my_writes_inline_never(&mut dst, src, BATCHES); | |
}) | |
}). | |
summarize("writer"); | |
} | |
#[inline(never)] | |
fn do_std_writes_inline_never<W: Writer>(dst: &mut W, src: &[u8], batches: uint) { | |
for _ in range(0, batches) { | |
dst.write(src).unwrap(); | |
} | |
} | |
#[inline(never)] | |
unsafe fn do_copy_nonoverlapping_memory_inline_never(mut dst: *mut u8, src: *const u8, len: uint, batches: uint) { | |
for _ in range(0, batches) { | |
ptr::copy_nonoverlapping_memory(dst, src, len); | |
dst = dst.offset(len as int); | |
} | |
} | |
trait MyWriter { | |
fn my_write(&mut self, src: &[u8]) -> IoResult<()>; | |
} | |
#[inline(never)] | |
fn do_my_writes_inline_never<W>(dst: &mut W, src: &[u8], batches: uint) where W: MyWriter { | |
for _ in range(0, batches) { | |
dst.my_write(src).unwrap(); | |
} | |
} | |
impl<'a> MyWriter for &'a mut [u8] { | |
#[inline] | |
fn my_write(&mut self, src: &[u8]) -> IoResult<()> { | |
if self.is_empty() { return Err(io::standard_error(io::EndOfFile)); } | |
let dst_len = self.len(); | |
let src_len = src.len(); | |
let write_len = min(dst_len, src_len); | |
slice::bytes::copy_memory(*self, src.slice_to(write_len)); | |
unsafe { | |
*self = mem::transmute(raw::Slice { | |
data: self.as_ptr().offset(write_len as int), | |
len: dst_len - write_len, | |
}); | |
} | |
if src_len > dst_len { | |
Err(io::standard_error(io::ShortWrite(write_len))) | |
} else { | |
Ok(()) | |
} | |
} | |
} | |
struct UnsafeWriter<'a> { | |
dst: *mut u8, | |
} | |
impl<'a> UnsafeWriter<'a> { | |
#[inline] | |
fn new(dst: &'a mut [u8]) -> UnsafeWriter<'a> { | |
UnsafeWriter { | |
dst: dst.as_mut_ptr(), | |
} | |
} | |
} | |
impl<'a> MyWriter for UnsafeWriter<'a> { | |
#[inline] | |
fn my_write(&mut self, src: &[u8]) -> IoResult<()> { | |
let len = src.len(); | |
unsafe { | |
ptr::copy_nonoverlapping_memory(self.dst, src.as_ptr(), len); | |
self.dst = self.dst.offset(len as int); | |
} | |
Ok(()) | |
} | |
} | |
struct BufWriter0<'a> { | |
dst: &'a mut [u8], | |
} | |
impl<'a> BufWriter0<'a> { | |
#[inline] | |
fn new<'a>(dst: &'a mut [u8]) -> BufWriter0<'a> { | |
BufWriter0 { | |
dst: dst | |
} | |
} | |
} | |
impl<'a> MyWriter for BufWriter0<'a> { | |
#[inline] | |
fn my_write(&mut self, src: &[u8]) -> IoResult<()> { | |
if self.dst.is_empty() { return Err(io::standard_error(io::EndOfFile)); } | |
let dst_len = self.dst.len(); | |
let src_len = src.len(); | |
let write_len = min(dst_len, src_len); | |
slice::bytes::copy_memory(self.dst, src.slice_to(write_len)); | |
unsafe { | |
self.dst = mem::transmute(raw::Slice { | |
data: self.dst.as_ptr().offset(write_len as int), | |
len: dst_len - write_len, | |
}); | |
} | |
if src_len > dst_len { | |
Err(io::standard_error(io::ShortWrite(write_len))) | |
} else { | |
Ok(()) | |
} | |
} | |
} | |
struct BufWriter1<'a> { | |
dst: &'a mut [u8], | |
} | |
impl<'a> BufWriter1<'a> { | |
#[inline] | |
fn new<'a>(dst: &'a mut [u8]) -> BufWriter1<'a> { | |
BufWriter1 { | |
dst: dst, | |
} | |
} | |
} | |
impl<'a> MyWriter for BufWriter1<'a> { | |
#[inline] | |
fn my_write(&mut self, src: &[u8]) -> IoResult<()> { | |
let dst_len = self.dst.len(); | |
let src_len = src.len(); | |
let write_len = min(dst_len, src_len); | |
slice::bytes::copy_memory(self.dst, src[..write_len]); | |
unsafe { | |
let self_: &mut raw::Slice<u8> = mem::transmute(self); | |
self_.data = self_.data.offset(write_len as int); | |
self_.len = dst_len - write_len; | |
} | |
Ok(()) | |
} | |
} | |
struct BufWriter2<'a> { | |
dst: &'a mut [u8], | |
} | |
impl<'a> BufWriter2<'a> { | |
#[inline] | |
fn new<'a>(dst: &'a mut [u8]) -> BufWriter2<'a> { | |
BufWriter2 { | |
dst: dst, | |
} | |
} | |
} | |
impl<'a> MyWriter for BufWriter2<'a> { | |
#[inline] | |
fn my_write(&mut self, src: &[u8]) -> IoResult<()> { | |
let dst_len = self.dst.len(); | |
let write_len = src.len(); | |
slice::bytes::copy_memory(self.dst, src[..write_len]); | |
unsafe { | |
let self_: &mut raw::Slice<u8> = mem::transmute(self); | |
self_.data = self_.data.offset(write_len as int); | |
self_.len = dst_len - write_len; | |
} | |
Ok(()) | |
} | |
} | |
struct BufWriter3<'a> { | |
dst: &'a mut [u8], | |
pos: uint, | |
} | |
impl<'a> BufWriter3<'a> { | |
#[inline] | |
fn new<'a>(dst: &'a mut [u8]) -> BufWriter3<'a> { | |
BufWriter3 { | |
dst: dst, | |
pos: 0, | |
} | |
} | |
} | |
impl<'a> MyWriter for BufWriter3<'a> { | |
#[inline] | |
fn my_write(&mut self, src: &[u8]) -> IoResult<()> { | |
// return an error if the entire write does not fit in the buffer | |
let cap = if self.pos >= self.dst.len() { 0 } else { self.dst.len() - self.pos }; | |
if src.len() > cap { | |
return Err(IoError { | |
kind: io::OtherIoError, | |
desc: "Trying to write past end of buffer", | |
detail: None | |
}) | |
} | |
slice::bytes::copy_memory(self.dst[mut self.pos..], src); | |
self.pos += src.len(); | |
Ok(()) | |
} | |
} | |
struct BufWriter4<'a> { | |
dst: *mut u8, | |
end: *mut u8, | |
} | |
impl<'a> BufWriter4<'a> { | |
#[inline] | |
fn new<'a>(dst: &'a mut [u8]) -> BufWriter4<'a> { | |
let dst_ptr = dst.as_mut_ptr(); | |
unsafe { | |
BufWriter4 { | |
dst: dst_ptr, | |
end: dst_ptr.offset(dst.len() as int), | |
} | |
} | |
} | |
#[inline] | |
fn capacity(&self) -> uint { | |
self.end as uint - self.dst as uint | |
} | |
} | |
impl<'a> MyWriter for BufWriter4<'a> { | |
#[inline] | |
fn my_write(&mut self, src: &[u8]) -> IoResult<()> { | |
let src_len = src.len(); | |
if src_len > self.capacity() { | |
return Err(IoError { | |
kind: io::OtherIoError, | |
desc: "Trying to write past end of buffer", | |
detail: None | |
}) | |
} | |
unsafe { | |
ptr::copy_nonoverlapping_memory(self.dst, src.as_ptr(), src_len); | |
self.dst = self.dst.offset(src_len as int); | |
} | |
Ok(()) | |
} | |
} | |
struct BufWriter5<'a> { | |
dst: &'a mut [u8], | |
} | |
impl<'a> BufWriter5<'a> { | |
#[inline] | |
fn new<'a>(dst: &'a mut [u8]) -> BufWriter5<'a> { | |
BufWriter5 { | |
dst: dst, | |
} | |
} | |
} | |
impl<'a> MyWriter for BufWriter5<'a> { | |
#[inline] | |
fn my_write(&mut self, src: &[u8]) -> IoResult<()> { | |
let dst_len = self.dst.len(); | |
let src_len = src.len(); | |
let x = (dst_len < src_len) as uint; | |
let write_len = dst_len * x + src_len * (1 - x); | |
slice::bytes::copy_memory(self.dst, src[..write_len]); | |
unsafe { | |
let self_: &mut raw::Slice<u8> = mem::transmute(self); | |
self_.data = self_.data.offset(write_len as int); | |
self_.len = dst_len - write_len; | |
} | |
Ok(()) | |
} | |
} | |
struct BufWriter6<'a> { | |
dst: &'a mut [u8], | |
} | |
impl<'a> BufWriter6<'a> { | |
#[inline] | |
fn new<'a>(dst: &'a mut [u8]) -> BufWriter6<'a> { | |
BufWriter6 { | |
dst: dst, | |
} | |
} | |
} | |
impl<'a> MyWriter for BufWriter6<'a> { | |
#[inline] | |
fn my_write(&mut self, src: &[u8]) -> IoResult<()> { | |
let dst_len = self.dst.len(); | |
let src_len = src.len(); | |
let write_len = min(dst_len, src_len); | |
unsafe { | |
ptr::copy_nonoverlapping_memory( | |
self.dst.as_mut_ptr(), | |
src.as_ptr(), | |
write_len); | |
let self_: &mut raw::Slice<u8> = mem::transmute(self); | |
self_.data = self_.data.offset(write_len as int); | |
self_.len = dst_len - write_len; | |
} | |
Ok(()) | |
} | |
} | |
struct BufWriter7<'a> { | |
dst: &'a mut [u8], | |
pos: uint, | |
} | |
impl<'a> BufWriter7<'a> { | |
#[inline] | |
fn new<'a>(dst: &'a mut [u8]) -> BufWriter7<'a> { | |
BufWriter7 { | |
dst: dst, | |
pos: 0, | |
} | |
} | |
} | |
impl<'a> MyWriter for BufWriter7<'a> { | |
#[inline] | |
fn my_write(&mut self, src: &[u8]) -> IoResult<()> { | |
// return an error if the entire write does not fit in the buffer | |
let dst_len = self.dst.len(); | |
let src_len = src.len(); | |
let cap = if self.pos >= dst_len { 0 } else { dst_len - self.pos }; | |
if src_len > cap { | |
return Err(IoError { | |
kind: io::OtherIoError, | |
desc: "Trying to write past end of buffer", | |
detail: None | |
}) | |
} | |
unsafe { | |
ptr::copy_nonoverlapping_memory( | |
self.dst.as_mut_ptr().offset(self.pos as int), | |
src.as_ptr(), | |
src_len); | |
} | |
self.pos += src_len; | |
Ok(()) | |
} | |
} | |
struct BufWriter8<'a> { | |
dst: *mut u8, | |
end: *mut u8, | |
} | |
impl<'a> BufWriter8<'a> { | |
#[inline] | |
fn new<'a>(dst: &'a mut [u8]) -> BufWriter8<'a> { | |
let dst_ptr = dst.as_mut_ptr(); | |
unsafe { | |
BufWriter8 { | |
dst: dst_ptr, | |
end: dst_ptr.offset(dst.len() as int), | |
} | |
} | |
} | |
} | |
impl<'a> MyWriter for BufWriter8<'a> { | |
#[inline] | |
fn my_write(&mut self, src: &[u8]) -> IoResult<()> { | |
let src_len = src.len(); | |
let cap = self.end as uint - self.dst as uint; | |
if src_len > cap { | |
return Err(IoError { | |
kind: io::OtherIoError, | |
desc: "Trying to write past end of buffer", | |
detail: None | |
}) | |
} | |
unsafe { | |
ptr::copy_nonoverlapping_memory(self.dst, src.as_ptr(), src_len); | |
self.dst = self.dst.offset(src_len as int); | |
} | |
Ok(()) | |
} | |
} | |
struct BufWriter9<'a> { | |
dst: *mut u8, | |
end: *mut u8, | |
} | |
impl<'a> BufWriter9<'a> { | |
#[inline] | |
fn new<'a>(dst: &'a mut [u8]) -> BufWriter9<'a> { | |
let dst_ptr = dst.as_mut_ptr(); | |
unsafe { | |
BufWriter9 { | |
dst: dst_ptr, | |
end: dst_ptr.offset(dst.len() as int), | |
} | |
} | |
} | |
} | |
impl<'a> MyWriter for BufWriter9<'a> { | |
#[inline] | |
fn my_write(&mut self, src: &[u8]) -> IoResult<()> { | |
unsafe { | |
let raw::Slice { data: src_ptr, len: src_len } = src.repr(); | |
let cap = self.end as uint - self.dst as uint; | |
if src_len > cap { | |
return Err(IoError { | |
kind: io::OtherIoError, | |
desc: "Trying to write past end of buffer", | |
detail: None | |
}) | |
} | |
ptr::copy_nonoverlapping_memory(self.dst, src_ptr, src_len); | |
self.dst = self.dst.offset(src_len as int); | |
} | |
Ok(()) | |
} | |
} | |
struct BufWriter10<'a> { | |
dst: &'a mut [u8], | |
pos: uint, | |
} | |
impl<'a> BufWriter10<'a> { | |
#[inline] | |
fn new<'a>(dst: &'a mut [u8]) -> BufWriter10<'a> { | |
BufWriter10 { | |
dst: dst, | |
pos: 0, | |
} | |
} | |
} | |
impl<'a> MyWriter for BufWriter10<'a> { | |
#[inline] | |
fn my_write(&mut self, src: &[u8]) -> IoResult<()> { | |
let dst_len = self.dst.len(); | |
let src_len = src.len(); | |
if self.pos == dst_len { return Err(io::standard_error(io::EndOfFile)); } | |
let cap = dst_len - self.pos; | |
let write_len = min(cap, src_len); | |
slice::bytes::copy_memory(self.dst[mut self.pos..], src[..write_len]); | |
if src_len > dst_len { | |
return Err(io::standard_error(io::ShortWrite(write_len))); | |
} | |
self.pos += write_len; | |
Ok(()) | |
} | |
} | |
struct BufWriter11<'a> { | |
dst: &'a mut [u8], | |
pos: uint, | |
} | |
impl<'a> BufWriter11<'a> { | |
#[inline] | |
fn new<'a>(dst: &'a mut [u8]) -> BufWriter11<'a> { | |
BufWriter11 { | |
dst: dst, | |
pos: 0, | |
} | |
} | |
} | |
impl<'a> MyWriter for BufWriter11<'a> { | |
#[inline] | |
fn my_write(&mut self, src: &[u8]) -> IoResult<()> { | |
let dst = self.dst[mut self.pos..]; | |
let dst_len = dst.len(); | |
if dst_len == 0 { | |
return Err(io::standard_error(io::EndOfFile)); | |
} | |
let src_len = src.len(); | |
if dst_len >= src_len { | |
unsafe { | |
ptr::copy_nonoverlapping_memory( | |
dst.as_mut_ptr(), | |
src.as_ptr(), | |
src_len); | |
} | |
self.pos += src_len; | |
Ok(()) | |
} else { | |
unsafe { | |
ptr::copy_nonoverlapping_memory( | |
dst.as_mut_ptr(), | |
src.as_ptr(), | |
dst_len); | |
} | |
self.pos += dst_len; | |
Err(io::standard_error(io::ShortWrite(dst_len))) | |
} | |
} | |
} | |
struct BufWriter12<'a> { | |
dst: &'a mut [u8], | |
} | |
impl<'a> BufWriter12<'a> { | |
#[inline] | |
fn new<'a>(dst: &'a mut [u8]) -> BufWriter12<'a> { | |
BufWriter12 { | |
dst: dst, | |
} | |
} | |
} | |
impl<'a> MyWriter for BufWriter12<'a> { | |
#[inline] | |
fn my_write(&mut self, src: &[u8]) -> IoResult<()> { | |
let dst_len = self.dst.len(); | |
if dst_len == 0 { | |
return Err(io::standard_error(io::EndOfFile)); | |
} | |
let src_len = src.len(); | |
if dst_len >= src_len { | |
unsafe { | |
ptr::copy_nonoverlapping_memory( | |
self.dst.as_mut_ptr(), | |
src.as_ptr(), | |
src_len); | |
self.dst = mem::transmute(raw::Slice { | |
data: self.dst.as_ptr().offset(src_len as int), | |
len: dst_len - src_len, | |
}); | |
} | |
Ok(()) | |
} else { | |
unsafe { | |
ptr::copy_nonoverlapping_memory( | |
self.dst.as_mut_ptr(), | |
src.as_ptr(), | |
dst_len); | |
self.dst = mem::transmute(raw::Slice { | |
data: self.dst.as_ptr().offset(dst_len as int), | |
len: 0, | |
}); | |
} | |
Err(io::standard_error(io::ShortWrite(dst_len))) | |
} | |
} | |
} | |
struct BufWriter13<'a> { | |
dst: *mut u8, | |
end: *mut u8, | |
} | |
impl<'a> BufWriter13<'a> { | |
#[inline] | |
fn new<'a>(dst: &'a mut [u8]) -> BufWriter13<'a> { | |
let dst_ptr = dst.as_mut_ptr(); | |
unsafe { | |
BufWriter13 { | |
dst: dst_ptr, | |
end: dst_ptr.offset(dst.len() as int), | |
} | |
} | |
} | |
} | |
impl<'a> MyWriter for BufWriter13<'a> { | |
#[inline] | |
fn my_write(&mut self, src: &[u8]) -> IoResult<()> { | |
let dst_len = self.end as uint - self.dst as uint; | |
if dst_len == 0 { | |
return Err(io::standard_error(io::EndOfFile)); | |
} | |
let src_len = src.len(); | |
if dst_len >= src_len { | |
unsafe { | |
ptr::copy_nonoverlapping_memory( | |
self.dst, | |
src.as_ptr(), | |
src_len); | |
self.dst = self.dst.offset(src_len as int); | |
} | |
Ok(()) | |
} else { | |
unsafe { | |
ptr::copy_nonoverlapping_memory( | |
self.dst, | |
src.as_ptr(), | |
dst_len); | |
self.dst = self.dst.offset(dst_len as int); | |
} | |
Err(io::standard_error(io::ShortWrite(dst_len))) | |
} | |
} | |
} | |
struct VecWriter1<'a> { | |
dst: &'a mut Vec<u8>, | |
} | |
impl<'a> VecWriter1<'a> { | |
#[inline] | |
fn new<'a>(dst: &'a mut Vec<u8>) -> VecWriter1<'a> { | |
VecWriter1 { | |
dst: dst, | |
} | |
} | |
} | |
impl<'a> MyWriter for VecWriter1<'a> { | |
#[inline] | |
fn my_write(&mut self, src: &[u8]) -> IoResult<()> { | |
let src_len = src.len(); | |
self.dst.reserve(src_len); | |
let dst = self.dst.as_mut_slice(); | |
unsafe { | |
// we reserved enough room in `dst` to store `src`. | |
ptr::copy_nonoverlapping_memory( | |
dst.as_mut_ptr(), | |
src.as_ptr(), | |
src_len); | |
} | |
Ok(()) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rustc -v | |
rustc 0.13.0-dev (22513fed3 2014-11-23 11:51:50 +0000) | |
$ cargo run --release | |
Compiling serial v0.0.1 (file:///home/japaric/tmp/serial) | |
Running `target/release/serial` | |
Benchmarking writer/std_vec_writer | |
> Warming up for 3.0000 s | |
> Collecting 100 samples in estimated 5.0010 s | |
> Found 9 outliers among 100 measurements (9.00%) | |
> 2 (2.00%) high mild | |
> 7 (7.00%) high severe | |
> Performing linear regression | |
> slope [537.25 ns 539.43 ns] | |
> R^2 0.9997506 0.9997316 | |
> Estimating the statistics of the sample | |
> mean [537.40 ns 538.98 ns] | |
> median [536.95 ns 537.39 ns] | |
> MAD [683.53 ps 1.3259 ns] | |
> SD [1.6395 ns 5.9119 ns] | |
Benchmarking writer/std_buf_writer | |
> Warming up for 3.0000 s | |
> Collecting 100 samples in estimated 5.0008 s | |
> Found 30 outliers among 100 measurements (30.00%) | |
> 21 (21.00%) low severe | |
> 1 (1.00%) high mild | |
> 8 (8.00%) high severe | |
> Performing linear regression | |
> slope [468.51 ns 472.35 ns] | |
> R^2 0.9987329 0.9986641 | |
> Estimating the statistics of the sample | |
> mean [465.94 ns 470.12 ns] | |
> median [467.38 ns 468.10 ns] | |
> MAD [1.2987 ns 4.1537 ns] | |
> SD [7.5682 ns 13.757 ns] | |
Benchmarking writer/copy_nonoverlapping | |
> Warming up for 3.0000 s | |
> Collecting 100 samples in estimated 5.0007 s | |
> Found 1 outliers among 100 measurements (1.00%) | |
> 1 (1.00%) high severe | |
> Performing linear regression | |
> slope [373.00 ns 375.26 ns] | |
> R^2 0.9992862 0.9992789 | |
> Estimating the statistics of the sample | |
> mean [374.98 ns 378.15 ns] | |
> median [372.06 ns 379.29 ns] | |
> MAD [3.8382 ns 8.3389 ns] | |
> SD [5.2964 ns 11.530 ns] | |
Benchmarking writer/slice_writer | |
> Warming up for 3.0000 s | |
> Collecting 100 samples in estimated 5.0002 s | |
> Found 12 outliers among 100 measurements (12.00%) | |
> 3 (3.00%) high mild | |
> 9 (9.00%) high severe | |
> Performing linear regression | |
> slope [454.08 ns 458.27 ns] | |
> R^2 0.9980865 0.9980152 | |
> Estimating the statistics of the sample | |
> mean [454.23 ns 458.97 ns] | |
> median [453.27 ns 453.79 ns] | |
> MAD [728.85 ps 1.3823 ns] | |
> SD [2.7254 ns 19.016 ns] | |
Benchmarking writer/unsafe_writer | |
> Warming up for 3.0000 s | |
> Collecting 100 samples in estimated 5.0018 s | |
> Found 3 outliers among 100 measurements (3.00%) | |
> 2 (2.00%) high mild | |
> 1 (1.00%) high severe | |
> Performing linear regression | |
> slope [375.24 ns 380.49 ns] | |
> R^2 0.9975203 0.9974504 | |
> Estimating the statistics of the sample | |
> mean [374.50 ns 377.55 ns] | |
> median [371.37 ns 374.38 ns] | |
> MAD [2.6494 ns 6.9383 ns] | |
> SD [5.7042 ns 9.9763 ns] | |
Benchmarking writer/buf_writer_0 | |
> Warming up for 3.0000 s | |
> Collecting 100 samples in estimated 5.0002 s | |
> Found 5 outliers among 100 measurements (5.00%) | |
> 3 (3.00%) high mild | |
> 2 (2.00%) high severe | |
> Performing linear regression | |
> slope [454.37 ns 455.40 ns] | |
> R^2 0.9999173 0.9999173 | |
> Estimating the statistics of the sample | |
> mean [454.28 ns 459.79 ns] | |
> median [453.58 ns 454.28 ns] | |
> MAD [1.0673 ns 2.0726 ns] | |
> SD [1.8856 ns 26.911 ns] | |
Benchmarking writer/buf_writer_1 | |
> Warming up for 3.0000 s | |
> Collecting 100 samples in estimated 5.0018 s | |
> Found 8 outliers among 100 measurements (8.00%) | |
> 6 (6.00%) high mild | |
> 2 (2.00%) high severe | |
> Performing linear regression | |
> slope [374.63 ns 379.03 ns] | |
> R^2 0.9984584 0.9984041 | |
> Estimating the statistics of the sample | |
> mean [374.10 ns 376.84 ns] | |
> median [372.38 ns 374.54 ns] | |
> MAD [1.6542 ns 3.8142 ns] | |
> SD [3.4032 ns 10.484 ns] | |
Benchmarking writer/buf_writer_2 | |
> Warming up for 3.0000 s | |
> Collecting 100 samples in estimated 5.0003 s | |
> Found 11 outliers among 100 measurements (11.00%) | |
> 9 (9.00%) high mild | |
> 2 (2.00%) high severe | |
> Performing linear regression | |
> slope [377.32 ns 382.30 ns] | |
> R^2 0.9978050 0.9977377 | |
> Estimating the statistics of the sample | |
> mean [377.10 ns 380.27 ns] | |
> median [374.80 ns 375.84 ns] | |
> MAD [1.8653 ns 3.7481 ns] | |
> SD [6.0423 ns 10.069 ns] | |
Benchmarking writer/buf_writer_3 | |
> Warming up for 3.0000 s | |
> Collecting 100 samples in estimated 5.0008 s | |
> Found 11 outliers among 100 measurements (11.00%) | |
> 3 (3.00%) high mild | |
> 8 (8.00%) high severe | |
> Performing linear regression | |
> slope [457.06 ns 460.68 ns] | |
> R^2 0.9990746 0.9990565 | |
> Estimating the statistics of the sample | |
> mean [456.57 ns 460.88 ns] | |
> median [455.23 ns 456.18 ns] | |
> MAD [1.5206 ns 2.7032 ns] | |
> SD [4.1343 ns 17.938 ns] | |
Benchmarking writer/buf_writer_4 | |
> Warming up for 3.0000 s | |
> Collecting 100 samples in estimated 5.0007 s | |
> Found 7 outliers among 100 measurements (7.00%) | |
> 6 (6.00%) high mild | |
> 1 (1.00%) high severe | |
> Performing linear regression | |
> slope [375.00 ns 377.60 ns] | |
> R^2 0.9991571 0.9991293 | |
> Estimating the statistics of the sample | |
> mean [376.76 ns 379.58 ns] | |
> median [374.15 ns 376.87 ns] | |
> MAD [2.6400 ns 6.0955 ns] | |
> SD [5.5173 ns 8.7718 ns] | |
Benchmarking writer/buf_writer_5 | |
> Warming up for 3.0000 s | |
> Collecting 100 samples in estimated 5.0016 s | |
> Found 14 outliers among 100 measurements (14.00%) | |
> 6 (6.00%) high mild | |
> 8 (8.00%) high severe | |
> Performing linear regression | |
> slope [456.81 ns 460.66 ns] | |
> R^2 0.9991028 0.9991032 | |
> Estimating the statistics of the sample | |
> mean [455.54 ns 458.00 ns] | |
> median [453.80 ns 455.09 ns] | |
> MAD [1.1937 ns 2.6578 ns] | |
> SD [4.1389 ns 8.5661 ns] | |
Benchmarking writer/buf_writer_6 | |
> Warming up for 3.0000 s | |
> Collecting 100 samples in estimated 5.0004 s | |
> Found 10 outliers among 100 measurements (10.00%) | |
> 7 (7.00%) high mild | |
> 3 (3.00%) high severe | |
> Performing linear regression | |
> slope [375.49 ns 379.41 ns] | |
> R^2 0.9984226 0.9984096 | |
> Estimating the statistics of the sample | |
> mean [374.95 ns 378.03 ns] | |
> median [372.67 ns 373.99 ns] | |
> MAD [1.7762 ns 3.8721 ns] | |
> SD [5.4738 ns 9.9718 ns] | |
Benchmarking writer/buf_writer_7 | |
> Warming up for 3.0000 s | |
> Collecting 100 samples in estimated 5.0021 s | |
> Found 11 outliers among 100 measurements (11.00%) | |
> 8 (8.00%) high mild | |
> 3 (3.00%) high severe | |
> Performing linear regression | |
> slope [419.41 ns 422.30 ns] | |
> R^2 0.9992863 0.9992814 | |
> Estimating the statistics of the sample | |
> mean [418.65 ns 420.83 ns] | |
> median [417.08 ns 417.66 ns] | |
> MAD [1.1419 ns 2.2675 ns] | |
> SD [3.7842 ns 7.4735 ns] | |
Benchmarking writer/buf_writer_8 | |
> Warming up for 3.0000 s | |
> Collecting 100 samples in estimated 5.0014 s | |
> Found 14 outliers among 100 measurements (14.00%) | |
> 8 (8.00%) high mild | |
> 6 (6.00%) high severe | |
> Performing linear regression | |
> slope [371.41 ns 372.61 ns] | |
> R^2 0.9998224 0.9998160 | |
> Estimating the statistics of the sample | |
> mean [371.55 ns 373.58 ns] | |
> median [370.98 ns 371.34 ns] | |
> MAD [450.40 ps 915.53 ps] | |
> SD [1.4768 ns 8.7942 ns] | |
Benchmarking writer/buf_writer_9 | |
> Warming up for 3.0000 s | |
> Collecting 100 samples in estimated 5.0013 s | |
> Found 8 outliers among 100 measurements (8.00%) | |
> 2 (2.00%) high mild | |
> 6 (6.00%) high severe | |
> Performing linear regression | |
> slope [371.44 ns 373.08 ns] | |
> R^2 0.9997608 0.9997474 | |
> Estimating the statistics of the sample | |
> mean [371.49 ns 373.16 ns] | |
> median [371.11 ns 371.32 ns] | |
> MAD [486.60 ps 1.0087 ns] | |
> SD [1.3319 ns 7.0311 ns] | |
Benchmarking writer/buf_writer_10 | |
> Warming up for 3.0000 s | |
> Collecting 100 samples in estimated 5.0014 s | |
> Found 7 outliers among 100 measurements (7.00%) | |
> 4 (4.00%) high mild | |
> 3 (3.00%) high severe | |
> Performing linear regression | |
> slope [416.19 ns 420.30 ns] | |
> R^2 0.9969632 0.9969171 | |
> Estimating the statistics of the sample | |
> mean [417.45 ns 423.30 ns] | |
> median [413.88 ns 416.50 ns] | |
> MAD [3.0064 ns 6.7434 ns] | |
> SD [8.0756 ns 22.256 ns] | |
Benchmarking writer/buf_writer_11 | |
> Warming up for 3.0000 s | |
> Collecting 100 samples in estimated 5.0005 s | |
> Found 13 outliers among 100 measurements (13.00%) | |
> 6 (6.00%) high mild | |
> 7 (7.00%) high severe | |
> Performing linear regression | |
> slope [415.91 ns 418.14 ns] | |
> R^2 0.9993625 0.9993541 | |
> Estimating the statistics of the sample | |
> mean [415.00 ns 417.39 ns] | |
> median [413.30 ns 414.78 ns] | |
> MAD [1.6892 ns 3.1366 ns] | |
> SD [4.1802 ns 7.9176 ns] | |
Benchmarking writer/buf_writer_12 | |
> Warming up for 3.0000 s | |
> Collecting 100 samples in estimated 5.0014 s | |
> Found 13 outliers among 100 measurements (13.00%) | |
> 3 (3.00%) high mild | |
> 10 (10.00%) high severe | |
> Performing linear regression | |
> slope [418.85 ns 425.14 ns] | |
> R^2 0.9974832 0.9974560 | |
> Estimating the statistics of the sample | |
> mean [418.10 ns 421.17 ns] | |
> median [416.48 ns 417.62 ns] | |
> MAD [1.2554 ns 2.3702 ns] | |
> SD [4.8903 ns 10.429 ns] | |
Benchmarking writer/buf_writer_13 | |
> Warming up for 3.0000 s | |
> Collecting 100 samples in estimated 5.0001 s | |
> Found 7 outliers among 100 measurements (7.00%) | |
> 7 (7.00%) high mild | |
> Performing linear regression | |
> slope [373.94 ns 376.04 ns] | |
> R^2 0.9991749 0.9991642 | |
> Estimating the statistics of the sample | |
> mean [377.22 ns 380.90 ns] | |
> median [373.38 ns 377.44 ns] | |
> MAD [3.2605 ns 8.3248 ns] | |
> SD [7.6051 ns 10.983 ns] | |
Benchmarking writer/vec_writer_1 | |
> Warming up for 3.0000 s | |
> Collecting 100 samples in estimated 5.0007 s | |
> Found 4 outliers among 100 measurements (4.00%) | |
> 4 (4.00%) high severe | |
> Performing linear regression | |
> slope [412.49 ns 413.66 ns] | |
> R^2 0.9998585 0.9998565 | |
> Estimating the statistics of the sample | |
> mean [412.74 ns 414.81 ns] | |
> median [411.85 ns 412.74 ns] | |
> MAD [1.1460 ns 2.4336 ns] | |
> SD [2.3169 ns 8.1519 ns] | |
Summarizing results of writer... DONE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment