Skip to content

Commit

Permalink
Add key! serde benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Dentosal committed Jan 17, 2024
1 parent 259d03a commit 696f49a
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion fuel-types/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use criterion::{
black_box,
criterion_group,
criterion_main,
Criterion,
Expand Down Expand Up @@ -106,5 +107,41 @@ pub fn criterion_benchmark(c: &mut Criterion) {
}
}

criterion_group!(benches, criterion_benchmark);
pub fn criterion_benchmark2(c: &mut Criterion) {
use fuel_types::Bytes32;

c.bench_function("serde_bincode_key_roundtrip_32", |b| {
let original = black_box(Bytes32::from([1u8; 32]));
b.iter(|| {
let serialized = black_box(bincode::serialize(&original)).unwrap();
let _: Bytes32 = black_box(bincode::deserialize(&serialized)).unwrap();
});
});

c.bench_function("serde_bincode_key_roundtrip_64", |b| {
let original = black_box(Bytes32::from([1u8; 32]));
b.iter(|| {
let serialized = black_box(bincode::serialize(&original)).unwrap();
let _: Bytes32 = black_box(bincode::deserialize(&serialized)).unwrap();
});
});

c.bench_function("serde_postcard_key_roundtrip_32", |b| {
let original = black_box(Bytes32::from([1u8; 32]));
b.iter(|| {
let serialized = black_box(postcard::to_stdvec(&original)).unwrap();
let _: Bytes32 = black_box(postcard::from_bytes(&serialized)).unwrap();
});
});

c.bench_function("serde_postcard_key_roundtrip_64", |b| {
let original = black_box(Bytes32::from([1u8; 32]));
b.iter(|| {
let serialized = black_box(postcard::to_stdvec(&original)).unwrap();
let _: Bytes32 = black_box(postcard::from_bytes(&serialized)).unwrap();
});
});
}

criterion_group!(benches, criterion_benchmark, criterion_benchmark2);
criterion_main!(benches);

0 comments on commit 696f49a

Please sign in to comment.