| 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 |
#include <deque> |
| 11 |
#include <ranges> |
| 12 |
|
| 13 |
#include "benchmark/benchmark.h" |
| 14 |
|
| 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); |
| 29 |
} |
| 30 |
|
| 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); |
| 37 |
|
| 38 |
for (auto _ : state) { |
| 39 |
benchmark::DoNotOptimize(input); |
| 40 |
benchmark::DoNotOptimize(output); |
| 41 |
std::ranges::copy(input | std::views::join, output.begin()); |
| 42 |
} |
| 43 |
} |
| 44 |
BENCHMARK(BM_join_view_in_vectors)->Apply(run_sizes); |
| 45 |
|
| 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); |
| 52 |
|
| 53 |
for (auto _ : state) { |
| 54 |
benchmark::DoNotOptimize(output); |
| 55 |
benchmark::DoNotOptimize(input); |
| 56 |
std::ranges::copy(input, (output | std::views::join).begin()); |
| 57 |
} |
| 58 |
} |
| 59 |
BENCHMARK(BM_join_view_out_vectors)->Apply(run_sizes); |
| 60 |
|
| 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); |
| 67 |
|
| 68 |
for (auto _ : state) { |
| 69 |
benchmark::DoNotOptimize(deque); |
| 70 |
benchmark::DoNotOptimize(output); |
| 71 |
std::ranges::copy(deque | std::views::join, output.begin()); |
| 72 |
} |
| 73 |
} |
| 74 |
BENCHMARK(BM_join_view_deques)->Apply(run_sizes); |
| 75 |
} // namespace |
| 76 |
|
| 77 |
BENCHMARK_MAIN(); |