1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
13 #include "benchmark/benchmark.h"
16 void run_sizes(auto benchmark
) {
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
);