| 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 | // UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 10 | |
| 11 | #include <algorithm> |
| 12 | #include <cassert> |
| 13 | |
| 14 | #include <benchmark/benchmark.h> |
| 15 | |
| 16 | void run_sizes(auto benchmark) { |
| 17 | benchmark->Arg(1) |
| 18 | ->Arg(2) |
| 19 | ->Arg(3) |
| 20 | ->Arg(4) |
| 21 | ->Arg(5) |
| 22 | ->Arg(6) |
| 23 | ->Arg(7) |
| 24 | ->Arg(8) |
| 25 | ->Arg(9) |
| 26 | ->Arg(10) |
| 27 | ->Arg(11) |
| 28 | ->Arg(12) |
| 29 | ->Arg(13) |
| 30 | ->Arg(14) |
| 31 | ->Arg(15) |
| 32 | ->Arg(16) |
| 33 | ->Arg(17) |
| 34 | ->Arg(18) |
| 35 | ->Arg(19) |
| 36 | ->Arg(20) |
| 37 | ->Arg(21) |
| 38 | ->Arg(22) |
| 39 | ->Arg(23) |
| 40 | ->Arg(24) |
| 41 | ->Arg(25) |
| 42 | ->Arg(26) |
| 43 | ->Arg(27) |
| 44 | ->Arg(28) |
| 45 | ->Arg(29) |
| 46 | ->Arg(30) |
| 47 | ->Arg(31) |
| 48 | ->Arg(32) |
| 49 | ->Arg(64) |
| 50 | ->Arg(512) |
| 51 | ->Arg(1024) |
| 52 | ->Arg(4000) |
| 53 | ->Arg(4096) |
| 54 | ->Arg(5500) |
| 55 | ->Arg(64000) |
| 56 | ->Arg(65536) |
| 57 | ->Arg(70000); |
| 58 | } |
| 59 | |
| 60 | template <class T> |
| 61 | static void BM_std_minmax(benchmark::State& state) { |
| 62 | std::vector<T> vec(state.range(), 3); |
| 63 | |
| 64 | for (auto _ : state) { |
| 65 | benchmark::DoNotOptimize(vec); |
| 66 | benchmark::DoNotOptimize(std::ranges::minmax(vec)); |
| 67 | } |
| 68 | } |
| 69 | BENCHMARK(BM_std_minmax<char>)->Apply(func: run_sizes); |
| 70 | BENCHMARK(BM_std_minmax<short>)->Apply(func: run_sizes); |
| 71 | BENCHMARK(BM_std_minmax<int>)->Apply(func: run_sizes); |
| 72 | BENCHMARK(BM_std_minmax<long long>)->Apply(func: run_sizes); |
| 73 | BENCHMARK(BM_std_minmax<unsigned char>)->Apply(func: run_sizes); |
| 74 | BENCHMARK(BM_std_minmax<unsigned short>)->Apply(func: run_sizes); |
| 75 | BENCHMARK(BM_std_minmax<unsigned int>)->Apply(func: run_sizes); |
| 76 | BENCHMARK(BM_std_minmax<unsigned long long>)->Apply(func: run_sizes); |
| 77 | |
| 78 | BENCHMARK_MAIN(); |
| 79 | |