Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / benchmarks / join_view.bench.cpp
blobc789a39a8e20801b5601f6faaa5e33c39afd94a3
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 //===----------------------------------------------------------------------===//
9 #include <algorithm>
10 #include <deque>
11 #include <ranges>
13 #include "benchmark/benchmark.h"
15 namespace {
16 void run_sizes(auto benchmark) {
17 benchmark->Arg(0)
18 ->Arg(1)
19 ->Arg(2)
20 ->Arg(64)
21 ->Arg(512)
22 ->Arg(1024)
23 ->Arg(4000)
24 ->Arg(4096)
25 ->Arg(5500)
26 ->Arg(64000)
27 ->Arg(65536)
28 ->Arg(70000);
31 void BM_join_view_in_vectors(benchmark::State& state) {
32 auto size = state.range(0);
33 std::vector<std::vector<int>> input(size, std::vector<int>(32));
34 std::ranges::fill(input | std::views::join, 10);
35 std::vector<int> output;
36 output.resize(size * 32);
38 for (auto _ : state) {
39 benchmark::DoNotOptimize(input);
40 benchmark::DoNotOptimize(output);
41 std::ranges::copy(input | std::views::join, output.begin());
44 BENCHMARK(BM_join_view_in_vectors)->Apply(run_sizes);
46 void BM_join_view_out_vectors(benchmark::State& state) {
47 auto size = state.range(0);
48 std::vector<std::vector<int>> output(size, std::vector<int>(32));
49 std::vector<int> input;
50 input.resize(size * 32);
51 std::ranges::fill(input, 10);
53 for (auto _ : state) {
54 benchmark::DoNotOptimize(output);
55 benchmark::DoNotOptimize(input);
56 std::ranges::copy(input, (output | std::views::join).begin());
59 BENCHMARK(BM_join_view_out_vectors)->Apply(run_sizes);
61 void BM_join_view_deques(benchmark::State& state) {
62 auto size = state.range(0);
63 std::deque<std::deque<int>> deque(size, std::deque<int>(32));
64 std::ranges::fill(deque | std::views::join, 10);
65 std::vector<int> output;
66 output.resize(size * 32);
68 for (auto _ : state) {
69 benchmark::DoNotOptimize(deque);
70 benchmark::DoNotOptimize(output);
71 std::ranges::copy(deque | std::views::join, output.begin());
74 BENCHMARK(BM_join_view_deques)->Apply(run_sizes);
75 } // namespace
77 BENCHMARK_MAIN();