-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Stephan T. Lavavej <[email protected]>
- Loading branch information
1 parent
64e410c
commit 2f6e7f8
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include <algorithm> | ||
#include <benchmark/benchmark.h> | ||
#include <cstddef> | ||
#include <cstdint> | ||
#include <ranges> | ||
|
||
enum class Op { | ||
FindSized, | ||
FindUnsized, | ||
Count, | ||
}; | ||
|
||
using namespace std; | ||
|
||
template <class T, size_t Size, size_t Pos, Op Operation> | ||
void bm(benchmark::State& state) { | ||
T a[Size]; | ||
|
||
fill_n(a, Size, T{'0'}); | ||
if constexpr (Pos < Size) { | ||
a[Pos] = T{'1'}; | ||
} else { | ||
static_assert(Operation != Op::FindUnsized); | ||
} | ||
|
||
for (auto _ : state) { | ||
if constexpr (Operation == Op::FindSized) { | ||
benchmark::DoNotOptimize(ranges::find(a, a + Size, T{'1'})); | ||
} else if constexpr (Operation == Op::FindUnsized) { | ||
benchmark::DoNotOptimize(ranges::find(a, unreachable_sentinel, T{'1'})); | ||
} else if constexpr (Operation == Op::Count) { | ||
benchmark::DoNotOptimize(ranges::count(a, a + Size, T{'1'})); | ||
} | ||
} | ||
} | ||
|
||
BENCHMARK(bm<uint8_t, 8021, 3056, Op::FindSized>); | ||
BENCHMARK(bm<uint8_t, 8021, 3056, Op::FindUnsized>); | ||
BENCHMARK(bm<uint8_t, 8021, 3056, Op::Count>); | ||
|
||
BENCHMARK(bm<uint16_t, 8021, 3056, Op::FindSized>); | ||
BENCHMARK(bm<uint16_t, 8021, 3056, Op::FindUnsized>); | ||
BENCHMARK(bm<uint16_t, 8021, 3056, Op::Count>); | ||
|
||
BENCHMARK(bm<uint32_t, 8021, 3056, Op::FindSized>); | ||
BENCHMARK(bm<uint32_t, 8021, 3056, Op::FindUnsized>); | ||
BENCHMARK(bm<uint32_t, 8021, 3056, Op::Count>); | ||
|
||
BENCHMARK(bm<uint64_t, 8021, 3056, Op::FindSized>); | ||
BENCHMARK(bm<uint64_t, 8021, 3056, Op::FindUnsized>); | ||
BENCHMARK(bm<uint64_t, 8021, 3056, Op::Count>); | ||
|
||
BENCHMARK(bm<int8_t, 8021, 3056, Op::FindSized>); | ||
BENCHMARK(bm<int8_t, 8021, 3056, Op::FindUnsized>); | ||
BENCHMARK(bm<int8_t, 8021, 3056, Op::Count>); | ||
|
||
BENCHMARK(bm<int16_t, 8021, 3056, Op::FindSized>); | ||
BENCHMARK(bm<int16_t, 8021, 3056, Op::FindUnsized>); | ||
BENCHMARK(bm<int16_t, 8021, 3056, Op::Count>); | ||
|
||
BENCHMARK(bm<int32_t, 8021, 3056, Op::FindSized>); | ||
BENCHMARK(bm<int32_t, 8021, 3056, Op::FindUnsized>); | ||
BENCHMARK(bm<int32_t, 8021, 3056, Op::Count>); | ||
|
||
BENCHMARK(bm<int64_t, 8021, 3056, Op::FindSized>); | ||
BENCHMARK(bm<int64_t, 8021, 3056, Op::FindUnsized>); | ||
BENCHMARK(bm<int64_t, 8021, 3056, Op::Count>); | ||
|
||
BENCHMARK_MAIN(); |