xref: /llvm-project/libcxx/test/benchmarks/algorithms/min.bench.cpp (revision e236a52a88956968f318fb908c584e5cb80b5b03)
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 #include "test_macros.h"
16 
17 void run_sizes(auto benchmark) {
18   benchmark->Arg(1)
19       ->Arg(2)
20       ->Arg(3)
21       ->Arg(4)
22       ->Arg(5)
23       ->Arg(6)
24       ->Arg(7)
25       ->Arg(8)
26       ->Arg(9)
27       ->Arg(10)
28       ->Arg(11)
29       ->Arg(12)
30       ->Arg(13)
31       ->Arg(14)
32       ->Arg(15)
33       ->Arg(16)
34       ->Arg(17)
35       ->Arg(18)
36       ->Arg(19)
37       ->Arg(20)
38       ->Arg(21)
39       ->Arg(22)
40       ->Arg(23)
41       ->Arg(24)
42       ->Arg(25)
43       ->Arg(26)
44       ->Arg(27)
45       ->Arg(28)
46       ->Arg(29)
47       ->Arg(30)
48       ->Arg(31)
49       ->Arg(32)
50       ->Arg(64)
51       ->Arg(512)
52       ->Arg(1024)
53       ->Arg(4000)
54       ->Arg(4096)
55       ->Arg(5500)
56       ->Arg(64000)
57       ->Arg(65536)
58       ->Arg(70000);
59 }
60 
61 template <class T>
62 static void BM_std_min(benchmark::State& state) {
63   std::vector<T> vec(state.range(), 3);
64 
65   for (auto _ : state) {
66     benchmark::DoNotOptimize(vec);
67     benchmark::DoNotOptimize(std::ranges::min(vec));
68   }
69 }
70 BENCHMARK(BM_std_min<char>)->Apply(run_sizes);
71 BENCHMARK(BM_std_min<short>)->Apply(run_sizes);
72 BENCHMARK(BM_std_min<int>)->Apply(run_sizes);
73 BENCHMARK(BM_std_min<long long>)->Apply(run_sizes);
74 #ifndef TEST_HAS_NO_INT128
75 BENCHMARK(BM_std_min<__int128>)->Apply(run_sizes);
76 #endif
77 BENCHMARK(BM_std_min<unsigned char>)->Apply(run_sizes);
78 BENCHMARK(BM_std_min<unsigned short>)->Apply(run_sizes);
79 BENCHMARK(BM_std_min<unsigned int>)->Apply(run_sizes);
80 BENCHMARK(BM_std_min<unsigned long long>)->Apply(run_sizes);
81 #ifndef TEST_HAS_NO_INT128
82 BENCHMARK(BM_std_min<unsigned __int128>)->Apply(run_sizes);
83 #endif
84 
85 BENCHMARK_MAIN();
86