@@ -23,6 +23,20 @@ int main(int argc, char** argv) {
23
23
auto std_find_first_of = [](auto first1, auto last1, auto first2, auto last2) {
24
24
return std::find_first_of (first1, last1, first2, last2);
25
25
};
26
+ auto std_find_first_of_pred = [](auto first1, auto last1, auto first2, auto last2) {
27
+ return std::find_first_of (first1, last1, first2, last2, [](auto x, auto y) {
28
+ benchmark::DoNotOptimize (x);
29
+ benchmark::DoNotOptimize (y);
30
+ return x == y;
31
+ });
32
+ };
33
+ auto ranges_find_first_of_pred = [](auto first1, auto last1, auto first2, auto last2) {
34
+ return std::ranges::find_first_of (first1, last1, first2, last2, [](auto x, auto y) {
35
+ benchmark::DoNotOptimize (x);
36
+ benchmark::DoNotOptimize (y);
37
+ return x == y;
38
+ });
39
+ };
26
40
27
41
// Benchmark {std,ranges}::find_first_of where we have a hit at 25% of the haystack
28
42
// and at the end of the needle. This measures how quickly we're able to search inside
@@ -55,6 +69,7 @@ int main(int argc, char** argv) {
55
69
->Arg (1024 )
56
70
->Arg (8192 );
57
71
};
72
+ // {std,ranges}::find_first_of(it1, it1, it2, it2)
58
73
bm.operator ()<std::vector<int >>(" std::find_first_of(vector<int>) (25% haystack, late needle)" , std_find_first_of);
59
74
bm.operator ()<std::deque<int >>(" std::find_first_of(deque<int>) (25% haystack, late needle)" , std_find_first_of);
60
75
bm.operator ()<std::list<int >>(" std::find_first_of(list<int>) (25% haystack, late needle)" , std_find_first_of);
@@ -64,6 +79,19 @@ int main(int argc, char** argv) {
64
79
" rng::find_first_of(deque<int>) (25% haystack, late needle)" , std::ranges::find_first_of);
65
80
bm.operator ()<std::list<int >>(
66
81
" rng::find_first_of(list<int>) (25% haystack, late needle)" , std::ranges::find_first_of);
82
+
83
+ // {std,ranges}::find_first_of(it1, it1, it2, it2, pred)
84
+ bm.operator ()<std::vector<int >>(
85
+ " std::find_first_of(vector<int>, pred) (25% haystack, late needle)" , std_find_first_of);
86
+ bm.operator ()<std::deque<int >>(
87
+ " std::find_first_of(deque<int>, pred) (25% haystack, late needle)" , std_find_first_of);
88
+ bm.operator ()<std::list<int >>(" std::find_first_of(list<int>, pred) (25% haystack, late needle)" , std_find_first_of);
89
+ bm.operator ()<std::vector<int >>(
90
+ " rng::find_first_of(vector<int>, pred) (25% haystack, late needle)" , std::ranges::find_first_of);
91
+ bm.operator ()<std::deque<int >>(
92
+ " rng::find_first_of(deque<int>, pred) (25% haystack, late needle)" , std::ranges::find_first_of);
93
+ bm.operator ()<std::list<int >>(
94
+ " rng::find_first_of(list<int>, pred) (25% haystack, late needle)" , std::ranges::find_first_of);
67
95
}
68
96
69
97
// Benchmark {std,ranges}::find_first_of where we have a hit at 90% of the haystack
@@ -97,6 +125,7 @@ int main(int argc, char** argv) {
97
125
->Arg (1024 )
98
126
->Arg (8192 );
99
127
};
128
+ // {std,ranges}::find_first_of(it1, it1, it2, it2)
100
129
bm.operator ()<std::vector<int >>(" std::find_first_of(vector<int>) (90% haystack, early needle)" , std_find_first_of);
101
130
bm.operator ()<std::deque<int >>(" std::find_first_of(deque<int>) (90% haystack, early needle)" , std_find_first_of);
102
131
bm.operator ()<std::list<int >>(" std::find_first_of(list<int>) (90% haystack, early needle)" , std_find_first_of);
@@ -106,6 +135,20 @@ int main(int argc, char** argv) {
106
135
" rng::find_first_of(deque<int>) (90% haystack, early needle)" , std::ranges::find_first_of);
107
136
bm.operator ()<std::list<int >>(
108
137
" rng::find_first_of(list<int>) (90% haystack, early needle)" , std::ranges::find_first_of);
138
+
139
+ // {std,ranges}::find_first_of(it1, it1, it2, it2, pred)
140
+ bm.operator ()<std::vector<int >>(
141
+ " std::find_first_of(vector<int>, pred) (90% haystack, early needle)" , std_find_first_of_pred);
142
+ bm.operator ()<std::deque<int >>(
143
+ " std::find_first_of(deque<int>, pred) (90% haystack, early needle)" , std_find_first_of_pred);
144
+ bm.operator ()<std::list<int >>(
145
+ " std::find_first_of(list<int>, pred) (90% haystack, early needle)" , std_find_first_of_pred);
146
+ bm.operator ()<std::vector<int >>(
147
+ " rng::find_first_of(vector<int>, pred) (90% haystack, early needle)" , ranges_find_first_of_pred);
148
+ bm.operator ()<std::deque<int >>(
149
+ " rng::find_first_of(deque<int>, pred) (90% haystack, early needle)" , ranges_find_first_of_pred);
150
+ bm.operator ()<std::list<int >>(
151
+ " rng::find_first_of(list<int>, pred) (90% haystack, early needle)" , ranges_find_first_of_pred);
109
152
}
110
153
111
154
benchmark::Initialize (&argc, argv);
0 commit comments