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 <cstring>
12#include <random>
13#include <vector>
14
15static void bm_vector_bool_count(benchmark::State& state) {
16 std::vector<bool> vec1(state.range(), false);
17
18 for (auto _ : state) {
19 benchmark::DoNotOptimize(vec1);
20 benchmark::DoNotOptimize(std::count(vec1.begin(), vec1.end(), true));
21 }
22}
23BENCHMARK(bm_vector_bool_count)->DenseRange(1, 8)->Range(16, 1 << 20);
24
25static void bm_vector_bool_ranges_count(benchmark::State& state) {
26 std::vector<bool> vec1(state.range(), false);
27
28 for (auto _ : state) {
29 benchmark::DoNotOptimize(vec1);
30 benchmark::DoNotOptimize(std::ranges::count(vec1.begin(), vec1.end(), true));
31 }
32}
33BENCHMARK(bm_vector_bool_ranges_count)->DenseRange(1, 8)->Range(16, 1 << 20);
34
35BENCHMARK_MAIN();
36