Skip to content

Commit

Permalink
chore(bench): avoid some data copy in benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
fu050409 committed May 17, 2024
1 parent f1e317e commit 156331a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion benches/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ use oblivion::{models::packet::OED, utils::generator::generate_random_salt};

fn criterion_benchmark_oed(c: &mut Criterion) {
let aes_key = generate_random_salt();
let long_data = vec![0u8; 1024 * 1024];
c.bench_function("oed", |b| {
b.iter(|| {
OED::new(&aes_key)
.from_bytes([0u8; 1e6 as usize].to_vec())
.from_bytes(long_data.clone())
.unwrap()
.plain_data()
.unwrap();
Expand Down
12 changes: 7 additions & 5 deletions benches/parser.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use criterion::{criterion_group, criterion_main, Criterion};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use oblivion::utils::parser::OblivionRequest;

fn criterion_benchmark_parser_request(c: &mut Criterion) {
c.bench_function("parser_request", |b| b.iter(|| {
let header = "GET / Oblivion/2.0";
OblivionRequest::new(&header).unwrap();
}));
let header = "GET / Oblivion/2.0";
c.bench_function("parser_request", |b| {
b.iter(|| {
OblivionRequest::new(black_box(&header)).unwrap();
})
});
}

criterion_group!(benches, criterion_benchmark_parser_request);
Expand Down

0 comments on commit 156331a

Please sign in to comment.