brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 31fb359 Raw
43 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 11#include <algorithm>12#include <numeric>13#include <random>14#include <vector>15 16#include "common.h"17 18namespace {19template <class ValueType>20struct LowerBound {21  size_t Quantity;22 23  mutable std::mt19937_64 rng{std::random_device{}()};24 25  void run(benchmark::State& state) const {26    runOpOnCopies<ValueType>(state, Quantity, Order::Ascending, BatchSize::CountBatch, [&](auto& Copy) {27      auto result = std::lower_bound(Copy.begin(), Copy.end(), Copy[rng() % Copy.size()]);28      benchmark::DoNotOptimize(result);29    });30  }31 32  std::string name() const { return "BM_LowerBound" + ValueType::name() + "_" + std::to_string(Quantity); }33};34} // namespace35 36int 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