xref: /openbsd-src/gnu/llvm/libcxx/benchmarks/algorithms/sort.bench.cpp (revision 3d61058aa5c692477b6d18acfbbdb653a9930ff9)
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 #include <algorithm>
10 
11 #include "common.h"
12 
13 namespace {
14 template <class ValueType, class Order>
15 struct Sort {
16   size_t Quantity;
17 
18   void run(benchmark::State& state) const {
19     runOpOnCopies<ValueType>(
20         state, Quantity, Order(), BatchSize::CountElements,
21         [](auto& Copy) { std::sort(Copy.begin(), Copy.end()); });
22   }
23 
24   bool skip() const { return Order() == ::Order::Heap; }
25 
26   std::string name() const {
27     return "BM_Sort" + ValueType::name() + Order::name() + "_" +
28            std::to_string(Quantity);
29   };
30 };
31 } // namespace
32 
33 int main(int argc, char** argv) {
34   benchmark::Initialize(&argc, argv);
35   if (benchmark::ReportUnrecognizedArguments(argc, argv))
36     return 1;
37   makeCartesianProductBenchmark<Sort, AllValueTypes, AllOrders>(Quantities);
38   benchmark::RunSpecifiedBenchmarks();
39 }
40