Debian Codegraph @

libcxx/benchmarks/algorithms/for_each.bench.cpp

raw
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 <deque>
12
13 static void bm_deque_for_each(benchmark::State& state) {
14 std::deque<char> vec1(state.range(), '1');
15 for (auto _ : state) {
16 benchmark::DoNotOptimize(vec1);
17 benchmark::DoNotOptimize(
18 std::for_each(vec1.begin(), vec1.end(), [](char& v) { v = std::clamp(v, (char)10, (char)100); }));
19 }
20 }
21 BENCHMARK(bm_deque_for_each)->DenseRange(1, 8)->Range(16, 1 << 20);
22
23 BENCHMARK_MAIN();