Skip to content

Commit

Permalink
Merge pull request #655 from Emurgo/evgenii/perfomace-test
Browse files Browse the repository at this point in the history
Benchmark
  • Loading branch information
lisicky authored Nov 14, 2024
2 parents c58a87c + ff47774 commit f02922f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
16 changes: 16 additions & 0 deletions rust/bench/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "bench"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cardano-serialization-lib = { path = ".." }

[dev-dependencies]
criterion = "0.5.1"

[[bench]]
name = "benches_main"
harness = false
7 changes: 7 additions & 0 deletions rust/bench/benches/benches_main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use criterion::criterion_main;

mod block_bench;

criterion_main! {
block_bench::benches
}
15 changes: 15 additions & 0 deletions rust/bench/benches/block_bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use cardano_serialization_lib::Block;
use criterion::{black_box, criterion_group, criterion_main, Criterion};

fn bench_decode_block(c: &mut Criterion) {
let raw_data = include_bytes!("data/block_with_certs.bin").to_vec();
c.bench_function("decode block", |b| {
b.iter(|| {
let data_copy = raw_data.clone();
let block = Block::from_bytes(data_copy);
assert!(block.is_ok());
})
});
}

criterion_group!(benches, bench_decode_block);
Binary file added rust/bench/benches/data/block_with_certs.bin
Binary file not shown.

0 comments on commit f02922f

Please sign in to comment.