diff --git a/rust/bench/Cargo.toml b/rust/bench/Cargo.toml new file mode 100644 index 00000000..85f47699 --- /dev/null +++ b/rust/bench/Cargo.toml @@ -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 \ No newline at end of file diff --git a/rust/bench/benches/benches_main.rs b/rust/bench/benches/benches_main.rs new file mode 100644 index 00000000..09de1cfc --- /dev/null +++ b/rust/bench/benches/benches_main.rs @@ -0,0 +1,7 @@ +use criterion::criterion_main; + +mod block_bench; + +criterion_main! { + block_bench::benches +} \ No newline at end of file diff --git a/rust/bench/benches/block_bench.rs b/rust/bench/benches/block_bench.rs new file mode 100644 index 00000000..37e67338 --- /dev/null +++ b/rust/bench/benches/block_bench.rs @@ -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); diff --git a/rust/bench/benches/data/block_with_certs.bin b/rust/bench/benches/data/block_with_certs.bin new file mode 100644 index 00000000..683fb98a Binary files /dev/null and b/rust/bench/benches/data/block_with_certs.bin differ