Skip to content

Commit bbafc39

Browse files
committed
expression: add parsing benchmark
1 parent 30d2d11 commit bbafc39

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/expression.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ where
260260

261261
#[cfg(test)]
262262
mod tests {
263-
264263
use super::parse_num;
265264

266265
#[test]
@@ -282,3 +281,30 @@ mod tests {
282281
assert_eq!(valid_chars, super::VALID_CHARS);
283282
}
284283
}
284+
285+
#[cfg(bench)]
286+
mod benches {
287+
use test::{black_box, Bencher};
288+
289+
use super::*;
290+
291+
#[bench]
292+
pub fn parse_tree(bh: &mut Bencher) {
293+
bh.iter(|| {
294+
let tree = Tree::from_str(
295+
"and(thresh(2,and(sha256(H),or(sha256(H),pk(A))),pk(B),pk(C),pk(D),sha256(H)),pk(E))",
296+
).unwrap();
297+
black_box(tree);
298+
});
299+
}
300+
301+
#[bench]
302+
pub fn parse_tree_deep(bh: &mut Bencher) {
303+
bh.iter(|| {
304+
let tree = Tree::from_str(
305+
"and(and(and(and(and(and(and(and(and(and(and(and(and(and(and(and(and(and(and(and(1,2),3),4),5),6),7),8),9),10),11),12),13),14),15),16),17),18),19),20),21)"
306+
).unwrap();
307+
black_box(tree);
308+
});
309+
}
310+
}

0 commit comments

Comments
 (0)