From a8e7ba54caf8ac0230eb3cbd0dc59333b3524cba Mon Sep 17 00:00:00 2001 From: lisicky Date: Tue, 12 Dec 2023 20:22:41 +0800 Subject: [PATCH] switch to criterion --- rust/bench/Cargo.toml | 16 ++++++++++++++++ rust/bench/benches/benches_main.rs | 7 +++++++ rust/bench/benches/block_bench.rs | 15 +++++++++++++++ rust/bench/benches/data/block_with_certs.bin | Bin 0 -> 1223 bytes 4 files changed, 38 insertions(+) create mode 100644 rust/bench/Cargo.toml create mode 100644 rust/bench/benches/benches_main.rs create mode 100644 rust/bench/benches/block_bench.rs create mode 100644 rust/bench/benches/data/block_with_certs.bin 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 0000000000000000000000000000000000000000..683fb98a4d1300d13f5dce6a05058555d1cfa258 GIT binary patch literal 1223 zcmV;&1UUPJf{Gdd2|xE50J#c&SRgRZH<;`JZq_-7vg8x}t@OR7PFr|bdvxBz=zx1a z(tubXPH#a?$n*lKckeLI{e>@I%wg{>!q0jZhi8PLY+e)C;J3`o(Q`KV( zu>7mP*C{^cT5EY+Qp-!$vpD(DAJ7LtZ_DVN2D>!z6j)Hw$oLnUfC;ddmtw3C#-$Y4 z(7bDH4MY>5?Y&*Th>DJKx`#~-DN?dexI+SUDsIX;2N6}{<7KwIT^lW4;N7(!S;mynjo@h!F7grtLFY?fv z;dJ8ZhMM={i8WfQ01k8&h|{>pF8W|&$UoyIw=TIqlfIyQTU(lP4xgUPAmnwJv(8rY zaI$Ek;^1}iNkZjE(vgDB&i%RPp&ha zhXEq4SqkhlXY^#wyrm3OG}1{QV;;LbgI_~vB1F8%IlY77#EDS6$2|UD>Z&0fmP^^a zwE3*kKi(1aY4+gzi_Ds&6ADz!t8;;tj%TeBk-Xc5C?boyx&9UREb%3@-W>h&-75`| zi8Oj?Wbu6E20L}%jnWSf&hGmSFIR!nN(1pjVXaG=%WOcyI^$-LZ)x2^E?+JHuhzTl zx(ABu#X4!lXQ*UUji4Z2*(o=)@4FJKNhdy8jy}cpTEEJ!Hpo^2Ol{|R=mlK|CV&=2KC`8s{2v|4dVhfQJNslT;ck+}igjYY6 zC0yR4AvDajd2oLyoya@D`#52lsm`SFuor!UgsrEJHY!mVVSAUr17v9eS?IpyB&d{0D^*8Aa9aKoygdnu5>hO z;^P^Y_`pn;f2*^|2K^U6=dU1#OISd|)Iz$R3<(vHezrhGU_NV*;KI)l$CkIlC-<66 zZkG{Byu0e>lR4XqRdYqajp6YF;T#|`G>9eMo5kcoP|*Q`SRi}g=WpR%>5j}l0_j~& z!Ex`1N^GJlb|c4MW}tr-^YmCimPDgLbtQi638Jv8Qp`5By#DH04I1a_)pi8VFuoes lp3bMheyz8cJPbeContUNNAXtsc6v&q7z|F-HX}a;pn$nUTCD&8 literal 0 HcmV?d00001