Debian Codegraph @

benchmarks/bench_str_search.cpp

raw
1 #include <benchmark/benchmark.h>
2 #include "frozen/algorithm.h"
3 #include <algorithm>
4 #include <functional>
5 #include <cstring>
6
7 static char const Words [] = R"(
8 Let it go, let it go
9 Can't hold it back anymore
10 Let it go, let it go
11 Turn my back and slam the door
12 The snow blows white on the mountain tonight
13 Not a footprint to be seen
14 A kingdom of isolation and it looks like I'm the queen
15 The wind is howling like the swirling storm inside
16 Couldn't keep it in
17 Heaven knows I try
18 Don't let them in, don't let them see
19 Be the good girl you always had to be
20 Conceal, don't feel, don't let them know
21 Well now they know
22 Let it go, let it go
23 Can't hold you back anymore
24 Let it go, let it go
25 Turn my back and slam the door
26 And here I stand
27 And here I'll stay
28 Let it go, let it go
29 The cold never bothered me anyway
30 It's funny how some distance makes everything seem small
31 And the fears that once controlled me can't get to me at all
32 Up here
33 )";
34
35 static auto * volatile WordsPtr = &Words;
36
37 static constexpr char Word[] = "controlled";
38
39 static void BM_StrFzSearchInBM(benchmark::State& state) {
40 for (auto _ : state) {
41 volatile bool status = frozen::search(std::begin(*WordsPtr), std::end(*WordsPtr), frozen::make_boyer_moore_searcher(Word));
42 }
43 }
44 BENCHMARK(BM_StrFzSearchInBM);
45
46 static void BM_StrStdSearchInBM(benchmark::State& state) {
47 for (auto _ : state) {
48 volatile bool status = std::search(std::begin(*WordsPtr), std::end(*WordsPtr),
49 std::boyer_moore_searcher<char const*>(std::begin(Word), std::end(Word)));
50 }
51 }
52 BENCHMARK(BM_StrStdSearchInBM);
53
54 static void BM_StrFzSearchInKMP(benchmark::State& state) {
55 for (auto _ : state) {
56 volatile bool status = frozen::search(std::begin(*WordsPtr), std::end(*WordsPtr), frozen::make_knuth_morris_pratt_searcher(Word));
57 }
58 }
59 BENCHMARK(BM_StrFzSearchInKMP);
60
61 #if 0
62 static void BM_StrStdSearchInStrStr(benchmark::State& state) {
63 for (auto _ : state) {
64 char const* volatile status = std::strstr(*WordsPtr, Word);
65 }
66 }
67 BENCHMARK(BM_StrStdSearchInStrStr);
68 #endif