• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use criterion::Criterion;
2 
3 use crate::define_aho_corasick;
4 
5 /// These benchmarks test various workloads on a corpus that corresponds to the
6 /// repetition of a single byte. For the most part, we compare the impact of
7 /// prefix optimizations on this case. Namely, if the repeated byte is `z` and
8 /// a prefix byte is `z`, then this represents the worst case for the prefix
9 /// optimizations.
all(c: &mut Criterion)10 pub fn all(c: &mut Criterion) {
11     define_same(c, "onebyte/match", 10_000, vec!["z"]);
12     define_same(c, "onebyte/nomatch", 0, vec!["a"]);
13 
14     define_same(c, "twobytes/match", 10_000, vec!["z", "a"]);
15     define_same(c, "twobytes/nomatch", 0, vec!["a", "b"]);
16 
17     define_same(c, "threebytes/match", 10_000, vec!["z", "a", "b"]);
18     define_same(c, "threebytes/nomatch", 0, vec!["a", "b", "c"]);
19 
20     define_same(c, "fourbytes/match", 10_000, vec!["z", "a", "b", "c"]);
21     define_same(c, "fourbytes/nomatch", 0, vec!["a", "b", "c", "d"]);
22 
23     define_same(c, "fivebytes/match", 10_000, vec!["z", "a", "b", "c", "d"]);
24     define_same(c, "fivebytes/nomatch", 0, vec!["a", "b", "c", "d", "e"]);
25 
26     define_same(c, "samebyte/match", 1_000, vec!["zzzzzzzzzz"]);
27 }
28 
define_same<B: AsRef<[u8]>>( c: &mut Criterion, bench_name: &str, count: usize, patterns: Vec<B>, )29 fn define_same<B: AsRef<[u8]>>(
30     c: &mut Criterion,
31     bench_name: &str,
32     count: usize,
33     patterns: Vec<B>,
34 ) {
35     let corpus = "z".repeat(10_000);
36     define_aho_corasick(
37         c,
38         "same",
39         bench_name,
40         corpus.as_bytes(),
41         count,
42         patterns,
43     );
44 }
45