From 408c608fc7bf1557ee987dd7fbe662fabed21a53 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 07:39:03 +0200 Subject: Adding upstream version 1.1.1. Signed-off-by: Daniel Baumann --- benchmarks/bench_int_set.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 benchmarks/bench_int_set.cpp (limited to 'benchmarks/bench_int_set.cpp') diff --git a/benchmarks/bench_int_set.cpp b/benchmarks/bench_int_set.cpp new file mode 100644 index 0000000..38fa7d3 --- /dev/null +++ b/benchmarks/bench_int_set.cpp @@ -0,0 +1,94 @@ +#include + +#include + +#include +#include +#include + +static constexpr frozen::set Keywords{ + 0, 2, 4, 6, 8, 10, 12, 14, + 16, 18, 20, 22, 24, 26, 28, 30, + 32, 34, 36, 38, 40, 42, 44, 46, + 48, 50, 52, 54, 56, 58, 60, 62 +}; + +static auto const* volatile Some = &Keywords; + +static void BM_IntInFzSet(benchmark::State& state) { + for (auto _ : state) { + for(auto kw : *Some) { + volatile bool status = Keywords.count(kw); + benchmark::DoNotOptimize(status); + } + } +} +BENCHMARK(BM_IntInFzSet); + +static const std::set Keywords_(Keywords.begin(), Keywords.end()); + +static void BM_IntInStdSet(benchmark::State& state) { + for (auto _ : state) { + for(auto kw : *Some) { + volatile bool status = Keywords_.count(kw); + benchmark::DoNotOptimize(status); + } + } +} + +BENCHMARK(BM_IntInStdSet); + +static const std::array Keywords__{{ + 0, 2, 4, 6, 8, 10, 12, 14, + 16, 18, 20, 22, 24, 26, 28, 30, + 32, 34, 36, 38, 40, 42, 44, 46, + 48, 50, 52, 54, 56, 58, 60, 62 +}}; +static void BM_IntInStdArray(benchmark::State& state) { + for (auto _ : state) { + for(auto kw : *Some) { + volatile bool status = std::find(Keywords__.begin(), Keywords__.end(), kw) != Keywords__.end(); + benchmark::DoNotOptimize(status); + } + } +} + +BENCHMARK(BM_IntInStdArray); + +static const int SomeInts[32] = { + 1, 3, 5, 7, 9, 11, 13, 15, + 17, 19, 21, 23, 25, 27, 29, 31, + 33, 35, 37, 39, 41, 43, 45, 47, + 49, 51, 53, 55, 57, 59, 61, 63 +}; +static auto const * volatile SomeIntsPtr = &SomeInts; + +static void BM_IntNotInFzSet(benchmark::State& state) { + for (auto _ : state) { + for(auto kw : *SomeIntsPtr) { + volatile bool status = Keywords.count(kw); + benchmark::DoNotOptimize(status); + } + } +} +BENCHMARK(BM_IntNotInFzSet); + +static void BM_IntNotInStdSet(benchmark::State& state) { + for (auto _ : state) { + for(auto kw : *SomeIntsPtr) { + volatile bool status = Keywords_.count(kw); + benchmark::DoNotOptimize(status); + } + } +} +BENCHMARK(BM_IntNotInStdSet); + +static void BM_IntNotInStdArray(benchmark::State& state) { + for (auto _ : state) { + for(auto kw : *SomeIntsPtr) { + volatile bool status = std::find(Keywords__.begin(), Keywords__.end(), kw) != Keywords__.end(); + benchmark::DoNotOptimize(status); + } + } +} +BENCHMARK(BM_IntNotInStdArray); -- cgit v1.2.3