Skip to content

Benchmarks for BufferedFoo #10441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/libstd/io/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,27 @@ mod test {
use super::*;
use io;
use super::super::mem::{MemReader, MemWriter};
use Harness = extra::test::BenchHarness;

/// A type, free to create, primarily intended for benchmarking creation of wrappers that, just
/// for construction, don't need a Reader/Writer that does anything useful. Is equivalent to
/// `/dev/null` in semantics.
#[deriving(Clone,Eq,Ord)]
pub struct NullStream;

impl Reader for NullStream {
fn read(&mut self, _: &mut [u8]) -> Option<uint> {
None
}

fn eof(&mut self) -> bool {
true
}
}

impl Writer for NullStream {
fn write(&mut self, _: &[u8]) { }
}

#[test]
fn test_buffered_reader() {
Expand Down Expand Up @@ -470,4 +491,25 @@ mod test {
writer.flush();
assert_eq!(*writer.inner_ref().inner_ref(), ~[0, 1, 0, '\n' as u8, 1]);
}

#[bench]
fn bench_buffered_reader(bh: &mut Harness) {
do bh.iter {
BufferedReader::new(NullStream);
}
}

#[bench]
fn bench_buffered_writer(bh: &mut Harness) {
do bh.iter {
BufferedWriter::new(NullStream);
}
}

#[bench]
fn bench_buffered_stream(bh: &mut Harness) {
do bh.iter {
BufferedStream::new(NullStream);
}
}
}