-
Notifications
You must be signed in to change notification settings - Fork 42
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
17 changed files
with
902 additions
and
16 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. |
23 changes: 23 additions & 0 deletions
23
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,23 @@ | ||
// Copyright (c) 2025 ESR Labs GmbH. All rights reserved. | ||
// | ||
// NOTICE: All information contained herein is, and remains | ||
// the property of E.S.R.Labs and its suppliers, if any. | ||
// The intellectual and technical concepts contained herein are | ||
// proprietary to E.S.R.Labs and its suppliers and may be covered | ||
// by German and Foreign Patents, patents in process, and are protected | ||
// by trade secret or copyright law. | ||
// Dissemination of this information or reproduction of this material | ||
// is strictly forbidden unless prior written permission is obtained | ||
// from E.S.R.Labs. | ||
|
||
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) | ||
} |
62 changes: 62 additions & 0 deletions
62
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,62 @@ | ||
// Copyright (c) 2025 ESR Labs GmbH. All rights reserved. | ||
// | ||
// NOTICE: All information contained herein is, and remains | ||
// the property of E.S.R.Labs and its suppliers, if any. | ||
// The intellectual and technical concepts contained herein are | ||
// proprietary to E.S.R.Labs and its suppliers and may be covered | ||
// by German and Foreign Patents, patents in process, and are protected | ||
// by trade secret or copyright law. | ||
// Dissemination of this information or reproduction of this material | ||
// is strictly forbidden unless prior written permission is obtained | ||
// from E.S.R.Labs. | ||
|
||
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); |
46 changes: 46 additions & 0 deletions
46
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,46 @@ | ||
#![allow(dead_code)] | ||
|
||
// Copyright (c) 2025 ESR Labs GmbH. All rights reserved. | ||
// | ||
// NOTICE: All information contained herein is, and remains | ||
// the property of E.S.R.Labs and its suppliers, if any. | ||
// The intellectual and technical concepts contained herein are | ||
// proprietary to E.S.R.Labs and its suppliers and may be covered | ||
// by German and Foreign Patents, patents in process, and are protected | ||
// by trade secret or copyright law. | ||
// Dissemination of this information or reproduction of this material | ||
// is strictly forbidden unless prior written permission is obtained | ||
// from E.S.R.Labs. | ||
|
||
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.