Skip to content

Instantly share code, notes, and snippets.

@fulmicoton
Last active September 25, 2017 00:31
Show Gist options
  • Save fulmicoton/a1fb87c3f3578f118552917636c95933 to your computer and use it in GitHub Desktop.
Save fulmicoton/a1fb87c3f3578f118552917636c95933 to your computer and use it in GitHub Desktop.
#![feature(test)]
extern crate test;
#[macro_use]
extern crate lazy_static;
#[cfg(test)]
mod tests {
use test::Bencher;
use std::io::Read;
lazy_static! {
static ref DATA: Vec<u8> = {
vec![0u8; 100]
};
}
#[bench]
fn bench_read_manual(b: &mut Bencher) {
let mut v: Vec<u8> = Vec::with_capacity(200);
b.iter(|| {
let mut data = DATA.as_slice();
v.clear();
let n = v.len();
v.extend_from_slice(data);
data = &data[n..];
});
}
#[bench]
fn bench_read_std(b: &mut Bencher) {
let mut v = Vec::with_capacity(200);
b.iter(|| {
let mut data = DATA.as_slice();
v.clear();
data.read_to_end(&mut v).unwrap();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment