-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(performance):
file-source
testing and benchmarks (#6742)
* Begin rework of `file-source` This commit is the start of a process to address #6730. The major changes introduced in this commit so far are application of clippy suggestions and model checks of the `read_until_with_max_size` test. I have a pretty good idea of how that function works now and will be introducing benchmarks. Signed-off-by: Brian L. Troutwine <brian@troutwine.us> * Clippy fixes Signed-off-by: Brian L. Troutwine <brian@troutwine.us> * Introduce benchmark In this commit I have introduce a benchmark for the read_until etc function. To do this I've had to make it part of the public API of the crate, but since the crate sits inside a larger project I'm less chuffed about this. I have fiddled with the test layout some as well. Signed-off-by: Brian L. Troutwine <brian@troutwine.us> * end Cargo.toml in newline Signed-off-by: Brian L. Troutwine <brian@troutwine.us> * Slim down the feature list slightly, relax bounds Signed-off-by: Brian L. Troutwine <brian@troutwine.us> * Reverse 'bytes' upgrade This crate looks to be challenging to upgrade. Best to do once tokio is updated in this project. Signed-off-by: Brian L. Troutwine <brian@troutwine.us> * Use libc on Windows Signed-off-by: Brian L. Troutwine <brian@troutwine.us> * remove unused file Signed-off-by: Brian L. Troutwine <brian@troutwine.us>
- Loading branch information
Showing
12 changed files
with
874 additions
and
629 deletions.
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
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,76 @@ | ||
use bytes::BytesMut; | ||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; | ||
use file_source::buffer::read_until_with_max_size; | ||
use std::fmt; | ||
use std::io::Cursor; | ||
|
||
struct Parameters { | ||
bytes: Vec<u8>, | ||
delim_offsets: Vec<usize>, | ||
delim: u8, | ||
bytes_before_first_delim: usize, | ||
max_size: u8, | ||
} | ||
|
||
impl fmt::Display for Parameters { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!( | ||
f, | ||
"bytes_before_first_delim: {}", | ||
self.bytes_before_first_delim, | ||
) | ||
} | ||
} | ||
|
||
fn read_until_bench(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("read_until"); | ||
|
||
let mut parameters = vec![ | ||
Parameters { | ||
bytes: vec![0; 1024], | ||
delim_offsets: vec![100, 500, 502], | ||
delim: 1, | ||
bytes_before_first_delim: 501, | ||
max_size: 1, | ||
}, | ||
Parameters { | ||
bytes: vec![0; 1024], | ||
delim_offsets: vec![900, 999, 1004, 1021, 1023], | ||
delim: 1, | ||
bytes_before_first_delim: 1022, | ||
max_size: 1, | ||
}, | ||
]; | ||
|
||
for param in &mut parameters { | ||
for offset in ¶m.delim_offsets { | ||
param.bytes[*offset] = param.delim; | ||
} | ||
} | ||
|
||
for param in ¶meters { | ||
group.throughput(Throughput::Bytes(param.bytes_before_first_delim as u64)); | ||
|
||
let mut position = 0; | ||
let mut buffer = BytesMut::with_capacity(param.max_size as usize); | ||
let mut reader = Cursor::new(¶m.bytes); | ||
let delimiter: [u8; 1] = [param.delim]; | ||
group.bench_with_input(BenchmarkId::from_parameter(¶m), ¶m, |b, _| { | ||
b.iter(|| { | ||
let _ = read_until_with_max_size( | ||
&mut reader, | ||
&mut position, | ||
&delimiter, | ||
&mut buffer, | ||
param.max_size as usize, | ||
); | ||
reader.set_position(0); | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
criterion_group!(name = benches; | ||
config = Criterion::default(); | ||
targets = read_until_bench); | ||
criterion_main!(benches); |
Oops, something went wrong.