48 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 <vector>13 14#include <benchmark/benchmark.h>15 16void run_sizes(auto benchmark) {17 benchmark->Arg(1)18 ->Arg(2)19 ->Arg(3)20 ->Arg(4)21 ->Arg(64)22 ->Arg(512)23 ->Arg(1024)24 ->Arg(4000)25 ->Arg(4096)26 ->Arg(5500)27 ->Arg(64000)28 ->Arg(65536)29 ->Arg(70000);30}31 32template <class T>33void BM_std_minmax_element(benchmark::State& state) {34 std::vector<T> vec(state.range(), 3);35 36 for (auto _ : state) {37 benchmark::DoNotOptimize(vec);38 benchmark::DoNotOptimize(std::minmax_element(vec.begin(), vec.end()));39 }40}41 42BENCHMARK(BM_std_minmax_element<char>)->Apply(run_sizes);43BENCHMARK(BM_std_minmax_element<short>)->Apply(run_sizes);44BENCHMARK(BM_std_minmax_element<int>)->Apply(run_sizes);45BENCHMARK(BM_std_minmax_element<long long>)->Apply(run_sizes);46 47BENCHMARK_MAIN();48