-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a BufReader benchmark for reads smaller than the buffer
- Loading branch information
Showing
4 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[workspace] | ||
members = ["hashmap"] | ||
members = ["hashmap", "bufreader"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "bufreader" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
benchlib = { path = "../../benchlib" } | ||
snap = "1.0.5" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use benchlib::benchmark::{black_box, BenchmarkSuite}; | ||
use snap::{read::FrameDecoder, write::FrameEncoder}; | ||
use std::io::{BufRead, BufReader, Write}; | ||
|
||
const BYTES: usize = 64 * 1024 * 1024; | ||
|
||
fn main() { | ||
let mut suite = BenchmarkSuite::new(); | ||
|
||
// Inspired by https://github.com/rust-lang/rust/issues/102727 | ||
// The pattern we want is a BufReader which wraps a Read impl where one Read::read call will | ||
// never fill the whole BufReader buffer. | ||
suite.register("bufreader-snappy", || { | ||
let data = vec![0u8; BYTES]; | ||
move || { | ||
let mut compressed = Vec::new(); | ||
FrameEncoder::new(&mut compressed) | ||
.write_all(&data[..]) | ||
.unwrap(); | ||
let mut reader = BufReader::with_capacity(BYTES, FrameDecoder::new(&compressed[..])); | ||
|
||
while let Ok(buf) = reader.fill_buf() { | ||
if buf.is_empty() { | ||
break; | ||
} | ||
black_box(buf); | ||
let len = buf.len(); | ||
reader.consume(len); | ||
} | ||
} | ||
}); | ||
|
||
suite.run().unwrap(); | ||
} |