Skip to content

Commit f02922f

Browse files
authored
Merge pull request #655 from Emurgo/evgenii/perfomace-test
Benchmark
2 parents c58a87c + ff47774 commit f02922f

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

rust/bench/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "bench"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
cardano-serialization-lib = { path = ".." }
10+
11+
[dev-dependencies]
12+
criterion = "0.5.1"
13+
14+
[[bench]]
15+
name = "benches_main"
16+
harness = false

rust/bench/benches/benches_main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use criterion::criterion_main;
2+
3+
mod block_bench;
4+
5+
criterion_main! {
6+
block_bench::benches
7+
}

rust/bench/benches/block_bench.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use cardano_serialization_lib::Block;
2+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
3+
4+
fn bench_decode_block(c: &mut Criterion) {
5+
let raw_data = include_bytes!("data/block_with_certs.bin").to_vec();
6+
c.bench_function("decode block", |b| {
7+
b.iter(|| {
8+
let data_copy = raw_data.clone();
9+
let block = Block::from_bytes(data_copy);
10+
assert!(block.is_ok());
11+
})
12+
});
13+
}
14+
15+
criterion_group!(benches, bench_decode_block);
1.19 KB
Binary file not shown.

0 commit comments

Comments
 (0)