1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include <algorithm>
10 #include <numeric>
11 #include <random>
12 #include <vector>
13 
14 #include "common.h"
15 
16 namespace {
17 template <class ValueType>
18 struct LowerBound {
19   size_t Quantity;
20 
21   mutable std::mt19937_64 rng { std::random_device{}() };
22 
run__anon165239aa0111::LowerBound23   void run(benchmark::State& state) const {
24     runOpOnCopies<ValueType>(state, Quantity, Order::Ascending, BatchSize::CountBatch, [&](auto& Copy) {
25       auto result = std::lower_bound(Copy.begin(), Copy.end(), Copy[rng() % Copy.size()]);
26       benchmark::DoNotOptimize(result);
27     });
28   }
29 
name__anon165239aa0111::LowerBound30   std::string name() const {
31     return "BM_LowerBound" + ValueType::name() + "_" + std::to_string(Quantity);
32   }
33 };
34 } // namespace
35 
main(int argc,char ** argv)36 int main(int argc, char** argv) {
37   benchmark::Initialize(&argc, argv);
38   if (benchmark::ReportUnrecognizedArguments(argc, argv))
39     return 1;
40   makeCartesianProductBenchmark<LowerBound, AllValueTypes>(Quantities);
41   benchmark::RunSpecifiedBenchmarks();
42 }
43