From ad075edd858065be20e4dfb66e085a7a857dae26 Mon Sep 17 00:00:00 2001 From: Shane Celis Date: Mon, 15 Apr 2024 00:19:53 -0400 Subject: [PATCH] test: Add benchmark for common_prefix_match. --- benches/bench.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/benches/bench.rs b/benches/bench.rs index 8374258..d23b8c6 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -232,6 +232,34 @@ mod trie { }, ); } + + pub fn common_prefix_match(_: &mut Criterion) { + let times = 100; + + super::c().bench_function( + &format!( + "[{}] Trie::common_prefix_match() {} times", + super::git_hash(), + times + ), + move |b| { + b.iter_batched( + || &TRIE_EDICT, + |trie| { + // iter_batched() does not properly time `routine` time when `setup` time is far longer than `routine` time. + // Tested function takes too short compared to build(). So loop many times. + let result = trie.common_prefix_search::, _>("すしをにぎる").next().is_some(); + for _ in 0..(times - 1) { + trie.common_prefix_search::, _>("すしをにぎる").next().is_some(); + } + + assert_eq!(result, true); + }, + BatchSize::SmallInput, + ) + }, + ); + } } criterion_group!( @@ -242,5 +270,6 @@ criterion_group!( trie::predictive_search_big_output, trie::predictive_search_limited_big_output, trie::common_prefix_search, + trie::common_prefix_match, ); criterion_main!(benches);