mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-30 19:06:04 +00:00

This patch fixes warnings and errors that come up when running the benchmarks as part of the test suite. It also adds the necessary Lit annotations to make it pass in various configurations and increases the portability of the benchmarks.
52 lines
1.5 KiB
C++
52 lines
1.5 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
|
|
|
#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();
|