-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
860 additions
and
47 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,19 @@ | ||
[package] | ||
name = "bufread" | ||
version = "0.1.1" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
|
||
[dev-dependencies] | ||
criterion.workspace = true | ||
proptest.workspace = true | ||
rand.workspace = true | ||
|
||
[[bench]] | ||
name = "buffer_benches" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "reader_benches" | ||
harness = false |
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,2 @@ | ||
# bufread | ||
A buffered reader implementation in Rust with special behavior. |
11 changes: 11 additions & 0 deletions
11
application/apps/indexer/addons/bufread/benches/bench_config.rs
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,11 @@ | ||
use criterion::Criterion; | ||
use std::time::Duration; | ||
|
||
pub fn bench_config(sample_size: usize) -> Criterion { | ||
Criterion::default() | ||
.warm_up_time(Duration::from_secs(5)) | ||
.measurement_time(Duration::from_secs(10)) | ||
.sample_size(sample_size) | ||
.significance_level(0.01) | ||
.noise_threshold(0.05) | ||
} |
50 changes: 50 additions & 0 deletions
50
application/apps/indexer/addons/bufread/benches/buffer_benches.rs
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,50 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use std::hint::black_box; | ||
|
||
#[path = "./bench_config.rs"] | ||
mod bench_config; | ||
use bench_config::bench_config; | ||
|
||
use bufread::DeqBuffer; | ||
|
||
fn write_buffer(buffer: &mut DeqBuffer, src: &[u8]) { | ||
while buffer.write_available() >= src.len() { | ||
buffer.write_from(src); | ||
} | ||
} | ||
|
||
fn write_buffer_benchmark(c: &mut Criterion) { | ||
let mut buffer = DeqBuffer::new(50 * 1000); | ||
let src: [u8; 100] = [1; 100]; | ||
|
||
c.bench_function("write_buffer", |b| { | ||
b.iter(|| write_buffer(black_box(&mut buffer), black_box(&src))) | ||
}); | ||
} | ||
|
||
fn write_read_buffer(buffer: &mut DeqBuffer, src: &[u8], dst: &mut [u8]) { | ||
while buffer.write_available() >= src.len() { | ||
buffer.write_from(src); | ||
} | ||
while buffer.read_available() != 0 { | ||
buffer.read_to(dst); | ||
} | ||
} | ||
|
||
fn write_read_buffer_benchmark(c: &mut Criterion) { | ||
let mut buffer = DeqBuffer::new(50 * 1000); | ||
let src: [u8; 100] = [1; 100]; | ||
let mut dst: [u8; 100] = [1; 100]; | ||
|
||
c.bench_function("write_read_buffer", |b| { | ||
b.iter(|| write_read_buffer(black_box(&mut buffer), black_box(&src), black_box(&mut dst))) | ||
}); | ||
} | ||
|
||
criterion_group! { | ||
name = benches; | ||
config = bench_config(1000); | ||
targets = write_buffer_benchmark, write_read_buffer_benchmark | ||
} | ||
|
||
criterion_main!(benches); |
34 changes: 34 additions & 0 deletions
34
application/apps/indexer/addons/bufread/benches/reader_benches.rs
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 @@ | ||
#![allow(dead_code)] | ||
|
||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use std::hint::black_box; | ||
|
||
#[path = "./bench_config.rs"] | ||
mod bench_config; | ||
use bench_config::bench_config; | ||
|
||
#[path = "../tests/proto.rs"] | ||
mod proto; | ||
|
||
use bufread::BufReader; | ||
use proto::{Parser, Source, MAX_PACKET_LEN}; | ||
|
||
fn proto_benchmark(c: &mut Criterion) { | ||
let source_min_size = 100 * MAX_PACKET_LEN; | ||
let buffer_max_size = 3 * MAX_PACKET_LEN; | ||
let buffer_min_size = MAX_PACKET_LEN; | ||
|
||
let source = Source::fixed(source_min_size); | ||
let reader = BufReader::new(buffer_max_size, buffer_min_size, source.data()); | ||
let mut parser = Parser::new(reader); | ||
|
||
c.bench_function("proto", |b| b.iter(|| Parser::run(black_box(&mut parser)))); | ||
} | ||
|
||
criterion_group! { | ||
name = benches; | ||
config = bench_config(1000); | ||
targets = proto_benchmark | ||
} | ||
|
||
criterion_main!(benches); |
Oops, something went wrong.