Skip to content

Commit 164bde9

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 bbafc39 commit 164bde9

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
@@ -1449,3 +1449,32 @@ mod tests {
14491449
}
14501450
}
14511451
}
1452+
1453+
#[cfg(bench)]
1454+
mod benches {
1455+
use test::{black_box, Bencher};
1456+
1457+
use super::*;
1458+
1459+
#[bench]
1460+
pub fn parse_segwit0(bh: &mut Bencher) {
1461+
bh.iter(|| {
1462+
let tree = Miniscript::<String, context::Segwitv0>::from_str_ext(
1463+
"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)))",
1464+
&ExtParams::sane(),
1465+
).unwrap();
1466+
black_box(tree);
1467+
});
1468+
}
1469+
1470+
#[bench]
1471+
pub fn parse_segwit0_deep(bh: &mut Bencher) {
1472+
bh.iter(|| {
1473+
let tree = Miniscript::<String, context::Segwitv0>::from_str_ext(
1474+
"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))",
1475+
&ExtParams::sane(),
1476+
).unwrap();
1477+
black_box(tree);
1478+
});
1479+
}
1480+
}

0 commit comments

Comments
 (0)