• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use criterion::Criterion;
2 
3 use crate::define_aho_corasick;
4 use crate::input::*;
5 
6 /// These benchmarks test various words on natural language text.
7 ///
8 /// These benchmarks were mostly taken from the regex crate's benchmarks. For
9 /// example, the case insensitive benchmarks below are the result of generating
10 /// all possible case variants for a fixed prefix of each string.
all(c: &mut Criterion)11 pub fn all(c: &mut Criterion) {
12     define_sherlock(c, "name/alt1", 158, vec!["Sherlock", "Street"]);
13     define_sherlock(c, "name/alt2", 558, vec!["Sherlock", "Holmes"]);
14     define_sherlock(
15         c,
16         "name/alt3",
17         740,
18         vec![
19             "Sherlock", "Holmes", "Watson", "Irene", "Adler", "John", "Baker",
20         ],
21     );
22     define_sherlock(c, "name/alt4", 582, vec!["Sher", "Hol"]);
23     define_sherlock(c, "name/alt5", 639, vec!["Sherlock", "Holmes", "Watson"]);
24     define_sherlock(
25         c,
26         "name/alt6",
27         0,
28         vec!["SherlockZ", "HolmesZ", "WatsonZ", "IreneZ", "MoriartyZ"],
29     );
30     define_sherlock(c, "name/alt7", 0, vec!["Шерлок Холмс", "Джон Уотсон"]);
31 
32     define_sherlock(
33         c,
34         "name/nocase1",
35         1764,
36         vec![
37             "ADL", "ADl", "AdL", "Adl", "BAK", "BAk", "BAK", "BaK", "Bak",
38             "BaK", "HOL", "HOl", "HoL", "Hol", "IRE", "IRe", "IrE", "Ire",
39             "JOH", "JOh", "JoH", "Joh", "SHE", "SHe", "ShE", "She", "WAT",
40             "WAt", "WaT", "Wat", "aDL", "aDl", "adL", "adl", "bAK", "bAk",
41             "bAK", "baK", "bak", "baK", "hOL", "hOl", "hoL", "hol", "iRE",
42             "iRe", "irE", "ire", "jOH", "jOh", "joH", "joh", "sHE", "sHe",
43             "shE", "she", "wAT", "wAt", "waT", "wat", "ſHE", "ſHe", "ſhE",
44             "ſhe",
45         ],
46     );
47     define_sherlock(
48         c,
49         "name/nocase2",
50         1307,
51         vec![
52             "HOL", "HOl", "HoL", "Hol", "SHE", "SHe", "ShE", "She", "hOL",
53             "hOl", "hoL", "hol", "sHE", "sHe", "shE", "she", "ſHE", "ſHe",
54             "ſhE", "ſhe",
55         ],
56     );
57     define_sherlock(
58         c,
59         "name/nocase3",
60         1442,
61         vec![
62             "HOL", "HOl", "HoL", "Hol", "SHE", "SHe", "ShE", "She", "WAT",
63             "WAt", "WaT", "Wat", "hOL", "hOl", "hoL", "hol", "sHE", "sHe",
64             "shE", "she", "wAT", "wAt", "waT", "wat", "ſHE", "ſHe", "ſhE",
65             "ſhe",
66         ],
67     );
68 
69     define_sherlock(c, "5000words", 567, words_5000());
70 }
71 
define_sherlock<B: AsRef<[u8]>>( c: &mut Criterion, bench_name: &str, count: usize, patterns: Vec<B>, )72 fn define_sherlock<B: AsRef<[u8]>>(
73     c: &mut Criterion,
74     bench_name: &str,
75     count: usize,
76     patterns: Vec<B>,
77 ) {
78     define_aho_corasick(c, "sherlock", bench_name, SHERLOCK, count, patterns);
79 }
80