@@ -38,7 +38,7 @@ int main(int argc, char** argv) {
38
38
});
39
39
};
40
40
41
- // Benchmark {std,ranges}::search_n where the needle is never found
41
+ // Benchmark {std,ranges}::search_n where the needle is never found (worst case).
42
42
{
43
43
auto bm = []<class Container >(std::string name, auto search_n) {
44
44
benchmark::RegisterBenchmark (
@@ -81,58 +81,6 @@ int main(int argc, char** argv) {
81
81
bm.operator ()<std::list<int >>(" rng::search_n(list<int>, pred) (no match)" , ranges_search_n_pred);
82
82
}
83
83
84
- // Benchmark {std,ranges}::search_n where we intersperse "near matches" inside the haystack
85
- {
86
- auto bm = []<class Container >(std::string name, auto search_n) {
87
- benchmark::RegisterBenchmark (
88
- name,
89
- [search_n](auto & st) {
90
- std::size_t const size = st.range (0 );
91
- using ValueType = typename Container::value_type;
92
- ValueType x = Generate<ValueType>::random ();
93
- ValueType y = random_different_from ({x});
94
- Container haystack (size, x);
95
- std::size_t n = size / 10 ; // needle size is 10% of the haystack
96
- assert (n > 0 );
97
-
98
- // intersperse near-matches inside the haystack
99
- {
100
- auto first = haystack.begin ();
101
- for (int i = 0 ; i != 10 ; ++i) {
102
- first = std::fill_n (first, n - 1 , y);
103
- ++first; // this causes the subsequence not to match because it has length n-1
104
- }
105
- }
106
-
107
- for ([[maybe_unused]] auto _ : st) {
108
- benchmark::DoNotOptimize (haystack);
109
- benchmark::DoNotOptimize (n);
110
- benchmark::DoNotOptimize (y);
111
- auto result = search_n (haystack.begin (), haystack.end (), n, y);
112
- benchmark::DoNotOptimize (result);
113
- }
114
- })
115
- ->Arg (1000 ) // non power-of-two
116
- ->Arg (1024 )
117
- ->Arg (8192 );
118
- };
119
- // {std,ranges}::search_n
120
- bm.operator ()<std::vector<int >>(" std::search_n(vector<int>) (near matches)" , std_search_n);
121
- bm.operator ()<std::deque<int >>(" std::search_n(deque<int>) (near matches)" , std_search_n);
122
- bm.operator ()<std::list<int >>(" std::search_n(list<int>) (near matches)" , std_search_n);
123
- bm.operator ()<std::vector<int >>(" rng::search_n(vector<int>) (near matches)" , std::ranges::search_n);
124
- bm.operator ()<std::deque<int >>(" rng::search_n(deque<int>) (near matches)" , std::ranges::search_n);
125
- bm.operator ()<std::list<int >>(" rng::search_n(list<int>) (near matches)" , std::ranges::search_n);
126
-
127
- // {std,ranges}::search_n(pred)
128
- bm.operator ()<std::vector<int >>(" std::search_n(vector<int>, pred) (near matches)" , std_search_n_pred);
129
- bm.operator ()<std::deque<int >>(" std::search_n(deque<int>, pred) (near matches)" , std_search_n_pred);
130
- bm.operator ()<std::list<int >>(" std::search_n(list<int>, pred) (near matches)" , std_search_n_pred);
131
- bm.operator ()<std::vector<int >>(" rng::search_n(vector<int>, pred) (near matches)" , ranges_search_n_pred);
132
- bm.operator ()<std::deque<int >>(" rng::search_n(deque<int>, pred) (near matches)" , ranges_search_n_pred);
133
- bm.operator ()<std::list<int >>(" rng::search_n(list<int>, pred) (near matches)" , ranges_search_n_pred);
134
- }
135
-
136
84
benchmark::Initialize (&argc, argv);
137
85
benchmark::RunSpecifiedBenchmarks ();
138
86
benchmark::Shutdown ();
0 commit comments