Skip to content

Commit f5c35c3

Browse files
committed
miniscript: add parsing benchmarks
On my system these show (the last two lines are the new ones) test expression::benches::parse_tree ... bench: 860 ns/iter (+/- 44) test expression::benches::parse_tree_deep ... bench: 1,481 ns/iter (+/- 66) test miniscript::benches::parse_segwit0 ... bench: 9,205 ns/iter (+/- 77) test miniscript::benches::parse_segwit0_deep ... bench: 23,003 ns/iter (+/- 248) As mentioned in the last commit message, these numbers are 10-20x the numbers for parsing expressions, meaning that optimizing the expression parser by itself will not get us a large performance boost.
1 parent 81f052a commit f5c35c3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/miniscript/mod.rs

+29
Original file line numberDiff line numberDiff line change
@@ -1450,3 +1450,32 @@ mod tests {
14501450
}
14511451
}
14521452
}
1453+
1454+
#[cfg(bench)]
1455+
mod benches {
1456+
use test::{black_box, Bencher};
1457+
1458+
use super::*;
1459+
1460+
#[bench]
1461+
pub fn parse_segwit0(bh: &mut Bencher) {
1462+
bh.iter(|| {
1463+
let tree = Miniscript::<String, context::Segwitv0>::from_str_ext(
1464+
"and_v(v:pk(E),thresh(2,j:and_v(v:sha256(H),t:or_i(v:sha256(H),v:pkh(A))),s:pk(B),s:pk(C),s:pk(D),sjtv:sha256(H)))",
1465+
&ExtParams::sane(),
1466+
).unwrap();
1467+
black_box(tree);
1468+
});
1469+
}
1470+
1471+
#[bench]
1472+
pub fn parse_segwit0_deep(bh: &mut Bencher) {
1473+
bh.iter(|| {
1474+
let tree = Miniscript::<String, context::Segwitv0>::from_str_ext(
1475+
"and_v(v:and_v(v:and_v(v:and_v(v:and_v(v:and_v(v:and_v(v:and_v(v:and_v(v:and_v(v:and_v(v:and_v(v:and_v(v:and_v(v:and_v(v:and_v(v:and_v(v:and_v(v:and_v(v:and_v(v:pk(1),pk(2)),pk(3)),pk(4)),pk(5)),pk(6)),pk(7)),pk(8)),pk(9)),pk(10)),pk(11)),pk(12)),pk(13)),pk(14)),pk(15)),pk(16)),pk(17)),pk(18)),pk(19)),pk(20)),pk(21))",
1476+
&ExtParams::sane(),
1477+
).unwrap();
1478+
black_box(tree);
1479+
});
1480+
}
1481+
}

0 commit comments

Comments
 (0)