-
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
077811d
commit 8057b59
Showing
7 changed files
with
94 additions
and
50 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
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 |
---|---|---|
@@ -1,54 +1,31 @@ | ||
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; | ||
use wiring::prelude::{BufUnWire, BufWire, Unwiring, Wiring}; | ||
|
||
pub fn bench<T: Wiring + Unwiring + PartialEq>(name: &'static str, c: &mut Criterion, data: &T) { | ||
const BUFFER_LEN: usize = 10_000_000; | ||
|
||
let mut group = c.benchmark_group(format!("{}/wiring", name)); | ||
|
||
let mut wire: Vec<u8> = Vec::with_capacity(BUFFER_LEN); | ||
let mut wire: Vec<u8> = Vec::new(); | ||
wire.reserve(BUFFER_LEN); // Optional | ||
|
||
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(); | ||
b.iter(|| { | ||
black_box(BufWire::new(&mut wire).wire(black_box(data)).unwrap()); | ||
}) | ||
}); | ||
|
||
let mut unwire = std::io::Cursor::new(wire); | ||
|
||
let buffer = wire.as_slice(); | ||
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, | ||
); | ||
b.iter(|| { | ||
black_box(BufUnWire::new(black_box(buffer)).unwire::<T>().unwrap()); | ||
}) | ||
}); | ||
|
||
crate::bench_size(name, "wiring", unwire.as_slice()); | ||
crate::bench_size(name, "wiring", wire.as_slice()); | ||
|
||
rt.block_on(async { | ||
let unwired = unwire.unwire::<T>().await.unwrap(); | ||
assert!(&unwired == data); | ||
}); | ||
let unwired: T = BufUnWire::new(buffer).unwire().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