Skip to content

Commit

Permalink
test: Add benchmark for common_prefix_match.
Browse files Browse the repository at this point in the history
  • Loading branch information
shanecelis committed Apr 15, 2024
1 parent 1d4d686 commit ad075ed
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<u8>, _>("すしをにぎる").next().is_some();
for _ in 0..(times - 1) {
trie.common_prefix_search::<Vec<u8>, _>("すしをにぎる").next().is_some();
}

assert_eq!(result, true);
},
BatchSize::SmallInput,
)
},
);
}
}

criterion_group!(
Expand All @@ -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);

0 comments on commit ad075ed

Please sign in to comment.