This is an intermediate and fairly mechanical step towards unifying the benchmarks with the rest of the test suite. Moving this around requires a few changes, notably making sure we don't throw a wrench into the discovery process of the normal test suite. This won't be a problem anymore once benchmarks are taken into account by the test setup out of the box.
50 lines
1.4 KiB
C++
50 lines
1.4 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include <algorithm>
|
|
#include <benchmark/benchmark.h>
|
|
#include <iterator>
|
|
#include <vector>
|
|
|
|
#include "test_iterators.h"
|
|
|
|
static void bm_contains_char(benchmark::State& state) {
|
|
std::vector<char> a(state.range(), 'a');
|
|
|
|
for (auto _ : state) {
|
|
benchmark::DoNotOptimize(a);
|
|
|
|
benchmark::DoNotOptimize(std::ranges::contains(a.begin(), a.end(), 'B'));
|
|
}
|
|
}
|
|
BENCHMARK(bm_contains_char)->RangeMultiplier(16)->Range(16, 16 << 20);
|
|
|
|
static void bm_contains_int(benchmark::State& state) {
|
|
std::vector<int> a(state.range(), 1);
|
|
|
|
for (auto _ : state) {
|
|
benchmark::DoNotOptimize(a);
|
|
|
|
benchmark::DoNotOptimize(std::ranges::contains(a.begin(), a.end(), 2));
|
|
}
|
|
}
|
|
BENCHMARK(bm_contains_int)->RangeMultiplier(16)->Range(16, 16 << 20);
|
|
|
|
static void bm_contains_bool(benchmark::State& state) {
|
|
std::vector<bool> a(state.range(), true);
|
|
|
|
for (auto _ : state) {
|
|
benchmark::DoNotOptimize(a);
|
|
|
|
benchmark::DoNotOptimize(std::ranges::contains(a.begin(), a.end(), false));
|
|
}
|
|
}
|
|
BENCHMARK(bm_contains_bool)->RangeMultiplier(16)->Range(16, 16 << 20);
|
|
|
|
BENCHMARK_MAIN();
|