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 <benchmark/benchmark.h>
11#include <vector>
12
13static void bm_fill_n(benchmark::State& state) {
14 std::vector<bool> vec1(state.range());
15 for (auto _ : state) {
16 benchmark::DoNotOptimize(vec1);
17 benchmark::DoNotOptimize(std::fill_n(vec1.begin(), vec1.size(), false));
18 }
19}
20BENCHMARK(bm_fill_n)->DenseRange(1, 8)->Range(16, 1 << 20);
21
22static void bm_ranges_fill_n(benchmark::State& state) {
23 std::vector<bool> vec1(state.range());
24 for (auto _ : state) {
25 benchmark::DoNotOptimize(vec1);
26 benchmark::DoNotOptimize(std::ranges::fill_n(vec1.begin(), vec1.size(), false));
27 }
28}
29BENCHMARK(bm_ranges_fill_n)->DenseRange(1, 8)->Range(16, 1 << 20);
30
31static void bm_fill(benchmark::State& state) {
32 std::vector<bool> vec1(state.range());
33 for (auto _ : state) {
34 benchmark::DoNotOptimize(vec1);
35 std::fill(vec1.begin(), vec1.end(), false);
36 }
37}
38BENCHMARK(bm_fill)->DenseRange(1, 8)->Range(16, 1 << 20);
39
40static void bm_ranges_fill(benchmark::State& state) {
41 std::vector<bool> vec1(state.range());
42 for (auto _ : state) {
43 benchmark::DoNotOptimize(vec1);
44 benchmark::DoNotOptimize(std::ranges::fill(vec1, false));
45 }
46}
47BENCHMARK(bm_ranges_fill)->DenseRange(1, 8)->Range(16, 1 << 20);
48
49BENCHMARK_MAIN();
50