-
Notifications
You must be signed in to change notification settings - Fork 58
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
df679e4
commit 1349761
Showing
8 changed files
with
103 additions
and
1 deletion.
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
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,54 @@ | ||
use criterion::{black_box, Criterion}; | ||
use tokio::runtime::Runtime; | ||
use wiring::prelude::{Unwire, Unwiring, Wire, Wiring}; | ||
use zstd::zstd_safe::WriteBuf; | ||
|
||
pub fn bench<'a, T>(name: &'static str, c: &mut Criterion, data: &'a T) | ||
where | ||
&'a T: Wiring, | ||
T: Unwiring + PartialEq, | ||
{ | ||
async fn wire_data<W: Wire, T: Wiring>(mut wire: W, data: T) { | ||
(&mut wire).wire(data).await.unwrap(); | ||
} | ||
|
||
let rt = Runtime::new().unwrap(); | ||
const BUFFER_LEN: usize = 50_000_000; | ||
|
||
let mut group = c.benchmark_group(format!("{}/wiring", name)); | ||
|
||
let mut wire: Vec<u8> = Vec::with_capacity(BUFFER_LEN); | ||
|
||
group.bench_function("serialize", |b| { | ||
b.to_async(Runtime::new().unwrap()).iter_batched( | ||
|| wire.clone(), | ||
|w| wire_data(black_box(w), black_box(data)), | ||
criterion::BatchSize::SmallInput, | ||
); | ||
}); | ||
|
||
rt.block_on(async { | ||
(&mut wire).wire(data).await.unwrap(); | ||
}); | ||
|
||
let mut unwire = std::io::Cursor::new(wire); | ||
|
||
group.bench_function("deserialize", |b| { | ||
b.to_async(Runtime::new().unwrap()).iter_batched( | ||
|| unwire.clone(), | ||
|w| async move { | ||
black_box(w).unwire::<T>().await.unwrap(); | ||
}, | ||
criterion::BatchSize::SmallInput, | ||
); | ||
}); | ||
|
||
crate::bench_size(name, "wiring", unwire.as_slice()); | ||
|
||
rt.block_on(async { | ||
let unwired = unwire.unwire::<T>().await.unwrap(); | ||
assert!(&unwired == data); | ||
}); | ||
|
||
group.finish(); | ||
} |
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
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
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