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

source code of libcxx/benchmarks/algorithms/minmax.bench.cpp