-
Notifications
You must be signed in to change notification settings - Fork 34
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
1 parent
fd1d297
commit 785be7c
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
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,42 @@ | ||
use criterion::criterion_group; | ||
use criterion::criterion_main; | ||
use criterion::BatchSize; | ||
use criterion::Criterion; | ||
use std::hint::black_box; | ||
use wtransport_proto::datagram::Datagram; | ||
use wtransport_proto::ids::QStreamId; | ||
|
||
const QSTREAM_ID: QStreamId = QStreamId::MAX; | ||
const PAYLOAD: &[u8] = b"Payload"; | ||
|
||
fn bench_datagram(c: &mut Criterion) { | ||
c.bench_function("read", |b| { | ||
b.iter_batched_ref( | ||
|| { | ||
let dgram = Datagram::new(QSTREAM_ID, PAYLOAD); | ||
let mut buffer = vec![0; dgram.write_size()]; | ||
dgram.write(&mut buffer).unwrap(); | ||
buffer | ||
}, | ||
|buffer| { | ||
let _ = black_box(Datagram::read(buffer)); | ||
}, | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
|
||
c.bench_function("write", |b| { | ||
b.iter_batched_ref( | ||
|| { | ||
let dgram = Datagram::new(QSTREAM_ID, PAYLOAD); | ||
let buffer = vec![0; dgram.write_size()]; | ||
(dgram, buffer) | ||
}, | ||
|(dgram, buffer)| dgram.write(buffer), | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
} | ||
|
||
criterion_group!(datagram, bench_datagram); | ||
criterion_main!(datagram); |