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
17void 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
61template <class T>
62static 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}
70BENCHMARK(BM_std_min<char>)->Apply(func: run_sizes);
71BENCHMARK(BM_std_min<short>)->Apply(func: run_sizes);
72BENCHMARK(BM_std_min<int>)->Apply(func: run_sizes);
73BENCHMARK(BM_std_min<long long>)->Apply(func: run_sizes);
74#ifndef TEST_HAS_NO_INT128
75BENCHMARK(BM_std_min<__int128>)->Apply(func: run_sizes);
76#endif
77BENCHMARK(BM_std_min<unsigned char>)->Apply(func: run_sizes);
78BENCHMARK(BM_std_min<unsigned short>)->Apply(func: run_sizes);
79BENCHMARK(BM_std_min<unsigned int>)->Apply(func: run_sizes);
80BENCHMARK(BM_std_min<unsigned long long>)->Apply(func: run_sizes);
81#ifndef TEST_HAS_NO_INT128
82BENCHMARK(BM_std_min<unsigned __int128>)->Apply(func: run_sizes);
83#endif
84
85BENCHMARK_MAIN();
86

source code of libcxx/test/benchmarks/algorithms/min.bench.cpp