Skip to content

Instantly share code, notes, and snippets.

@alexcrichton
Forked from anonymous/foo.rs
Created April 3, 2015 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexcrichton/31122565e893d6599453 to your computer and use it in GitHub Desktop.
Save alexcrichton/31122565e893d6599453 to your computer and use it in GitHub Desktop.
running 5 tests
test read_to_end_doesnt_expand_capacity_unless_necessary ... ignored
test read_to_end_1024 ... bench: 53 ns/iter (+/- 1)
test read_to_end_64k ... bench: 1776 ns/iter (+/- 27)
test read_to_end_normal_test ... bench: 7 ns/iter (+/- 1)
test read_to_end_small_test ... bench: 6 ns/iter (+/- 1)
test result: ok. 0 passed; 0 failed; 1 ignored; 4 measured
running 5 tests
test read_to_end_doesnt_expand_capacity_unless_necessary ... ignored
test read_to_end_1024 ... bench: 44 ns/iter (+/- 2)
test read_to_end_64k ... bench: 1807 ns/iter (+/- 37)
test read_to_end_normal_test ... bench: 46 ns/iter (+/- 1)
test read_to_end_small_test ... bench: 46 ns/iter (+/- 1)
test result: ok. 0 passed; 0 failed; 1 ignored; 4 measured
#![feature(test)]
extern crate test;
use std::io::Read;
#[bench]
fn read_to_end_1024(b: &mut test::Bencher) {
let buf = [1u8; 1024];
let mut src = &buf[..];
b.iter(|| {
let mut dst = Vec::with_capacity(1024);
src.read_to_end(&mut dst)
});
}
#[bench]
fn read_to_end_64k(b: &mut test::Bencher) {
let buf = [1u8; 1024 * 64];
let mut src = &buf[..];
b.iter(|| {
let mut dst = Vec::with_capacity(64 * 1024);
src.read_to_end(&mut dst)
});
}
#[bench]
fn read_to_end_normal_test(b: &mut test::Bencher) {
let buf = [1u8; 100000];
let mut src = &buf[..];
b.iter(|| {
let mut dst = Vec::new();
src.read_to_end(&mut dst)
});
}
#[bench]
fn read_to_end_small_test(b: &mut test::Bencher) {
let buf = [1u8; 1000];
let mut src = &buf[..];
b.iter(|| {
let mut dst = Vec::new();
src.read_to_end(&mut dst)
});
}
#[test]
fn read_to_end_doesnt_expand_capacity_unless_necessary() {
const BUF_SIZE: usize = 1024;
let buf = [1u8; BUF_SIZE];
let mut src = &buf[..];
let mut dst = Vec::with_capacity(BUF_SIZE);
let init_capacity = dst.capacity();
assert_eq!(src.read_to_end(&mut dst).unwrap(), BUF_SIZE);
assert_eq!(init_capacity, dst.capacity());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment