@@ -39,62 +39,8 @@ int main(int argc, char** argv) {
3939 return !std::ranges::none_of (first, last, pred);
4040 };
4141
42- // Benchmark {std,ranges}::{any_of,all_of,none_of} where we bail out early
43- // (after visiting 25% of the elements).
44- {
45- auto bm = []<class Container >(std::string name, auto any_of) {
46- benchmark::RegisterBenchmark (
47- name,
48- [any_of](auto & st) {
49- std::size_t const size = st.range (0 );
50- using ValueType = typename Container::value_type;
51- ValueType x = Generate<ValueType>::random ();
52- ValueType y = random_different_from ({x});
53- Container c (size, x);
54- *std::next (c.begin (), size / 4 ) = y; // bail out after the first 25% elements
55-
56- for (auto _ : st) {
57- benchmark::DoNotOptimize (c);
58- auto result = any_of (c.begin (), c.end (), [&](auto element) {
59- benchmark::DoNotOptimize (element);
60- return element == y;
61- });
62- benchmark::DoNotOptimize (result);
63- }
64- })
65- ->Arg (8 )
66- ->Arg (32 )
67- ->Arg (50 ) // non power-of-two
68- ->Arg (8192 )
69- ->Arg (32768 );
70- };
71-
72- // any_of
73- bm.operator ()<std::vector<int >>(" std::any_of(vector<int>) (bail 25%)" , std_any_of);
74- bm.operator ()<std::deque<int >>(" std::any_of(deque<int>) (bail 25%)" , std_any_of);
75- bm.operator ()<std::list<int >>(" std::any_of(list<int>) (bail 25%)" , std_any_of);
76- bm.operator ()<std::vector<int >>(" rng::any_of(vector<int>) (bail 25%)" , std::ranges::any_of);
77- bm.operator ()<std::deque<int >>(" rng::any_of(deque<int>) (bail 25%)" , std::ranges::any_of);
78- bm.operator ()<std::list<int >>(" rng::any_of(list<int>) (bail 25%)" , std::ranges::any_of);
79-
80- // all_of
81- bm.operator ()<std::vector<int >>(" std::all_of(vector<int>) (bail 25%)" , std_all_of);
82- bm.operator ()<std::deque<int >>(" std::all_of(deque<int>) (bail 25%)" , std_all_of);
83- bm.operator ()<std::list<int >>(" std::all_of(list<int>) (bail 25%)" , std_all_of);
84- bm.operator ()<std::vector<int >>(" rng::all_of(vector<int>) (bail 25%)" , ranges_all_of);
85- bm.operator ()<std::deque<int >>(" rng::all_of(deque<int>) (bail 25%)" , ranges_all_of);
86- bm.operator ()<std::list<int >>(" rng::all_of(list<int>) (bail 25%)" , ranges_all_of);
87-
88- // none_of
89- bm.operator ()<std::vector<int >>(" std::none_of(vector<int>) (bail 25%)" , std_none_of);
90- bm.operator ()<std::deque<int >>(" std::none_of(deque<int>) (bail 25%)" , std_none_of);
91- bm.operator ()<std::list<int >>(" std::none_of(list<int>) (bail 25%)" , std_none_of);
92- bm.operator ()<std::vector<int >>(" rng::none_of(vector<int>) (bail 25%)" , ranges_none_of);
93- bm.operator ()<std::deque<int >>(" rng::none_of(deque<int>) (bail 25%)" , ranges_none_of);
94- bm.operator ()<std::list<int >>(" rng::none_of(list<int>) (bail 25%)" , ranges_none_of);
95- }
96-
97- // Benchmark {std,ranges}::{any_of,all_of,none_of} where we process the whole sequence.
42+ // Benchmark {std,ranges}::{any_of,all_of,none_of} where we process the whole sequence,
43+ // which is the worst case.
9844 {
9945 auto bm = []<class Container >(std::string name, auto any_of) {
10046 benchmark::RegisterBenchmark (
0 commit comments