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 <iterator> |
12 | #include <vector> |
13 | |
14 | #include "test_iterators.h" |
15 | |
16 | static void bm_contains_char(benchmark::State& state) { |
17 | std::vector<char> a(state.range(), 'a'); |
18 | |
19 | for (auto _ : state) { |
20 | benchmark::DoNotOptimize(a); |
21 | |
22 | benchmark::DoNotOptimize(std::ranges::contains(a.begin(), a.end(), 'B')); |
23 | } |
24 | } |
25 | BENCHMARK(bm_contains_char)->RangeMultiplier(multiplier: 16)->Range(start: 16, limit: 16 << 20); |
26 | |
27 | static void bm_contains_int(benchmark::State& state) { |
28 | std::vector<int> a(state.range(), 1); |
29 | |
30 | for (auto _ : state) { |
31 | benchmark::DoNotOptimize(value&: a); |
32 | |
33 | benchmark::DoNotOptimize(std::ranges::contains(a.begin(), a.end(), 2)); |
34 | } |
35 | } |
36 | BENCHMARK(bm_contains_int)->RangeMultiplier(multiplier: 16)->Range(start: 16, limit: 16 << 20); |
37 | |
38 | static void bm_contains_bool(benchmark::State& state) { |
39 | std::vector<bool> a(state.range(), true); |
40 | |
41 | for (auto _ : state) { |
42 | benchmark::DoNotOptimize(value&: a); |
43 | |
44 | benchmark::DoNotOptimize(std::ranges::contains(a.begin(), a.end(), false)); |
45 | } |
46 | } |
47 | BENCHMARK(bm_contains_bool)->RangeMultiplier(multiplier: 16)->Range(start: 16, limit: 16 << 20); |
48 | |
49 | BENCHMARK_MAIN(); |
50 | |