//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 #include #include #include #include #include #include #include #include "../../GenerateInput.h" int main(int argc, char** argv) { // Benchmark ranges::contains where we process the whole sequence, which is the // worst case. { auto bm = [](std::string name) { benchmark::RegisterBenchmark( name, [](auto& st) { std::size_t const size = st.range(0); using ValueType = typename Container::value_type; ValueType x = Generate::random(); ValueType y = random_different_from({x}); Container c(size, x); auto first = c.begin(); auto last = c.end(); for ([[maybe_unused]] auto _ : st) { benchmark::DoNotOptimize(c); benchmark::DoNotOptimize(y); auto result = std::ranges::contains(first, last, y); benchmark::DoNotOptimize(result); } }) ->Arg(8) ->Arg(32) ->Arg(50) // non power-of-two ->Arg(8192) ->Arg(1 << 20); }; bm.operator()>("rng::contains(vector) (process all)"); bm.operator()>("rng::contains(deque) (process all)"); bm.operator()>("rng::contains(list) (process all)"); } benchmark::Initialize(&argc, argv); benchmark::RunSpecifiedBenchmarks(); benchmark::Shutdown(); return 0; }