Commit 3be31775 by Abseil Team Committed by Copybara-Service

Add a new microbenchmark for spinlock TryLock and codegen functions.

PiperOrigin-RevId: 579852413
Change-Id: I1eddd70a4bee974e3a5109109ddfc4b4fd8f421e
parent 1cb3345d
......@@ -24,8 +24,22 @@
namespace {
template <absl::base_internal::SchedulingMode scheduling_mode>
static void BM_TryLock(benchmark::State& state) {
// Ensure a ThreadIdentity is installed so that KERNEL_ONLY has an effect.
ABSL_INTERNAL_CHECK(
absl::synchronization_internal::GetOrCreateCurrentThreadIdentity() !=
nullptr,
"GetOrCreateCurrentThreadIdentity() failed");
static auto* spinlock = new absl::base_internal::SpinLock(scheduling_mode);
for (auto _ : state) {
if (spinlock->TryLock()) spinlock->Unlock();
}
}
template <absl::base_internal::SchedulingMode scheduling_mode>
static void BM_SpinLock(benchmark::State& state) {
// Ensure a ThreadIdentity is installed.
// Ensure a ThreadIdentity is installed so that KERNEL_ONLY has an effect.
ABSL_INTERNAL_CHECK(
absl::synchronization_internal::GetOrCreateCurrentThreadIdentity() !=
nullptr,
......@@ -49,4 +63,15 @@ BENCHMARK_TEMPLATE(BM_SpinLock,
->Threads(1)
->ThreadPerCpu();
BENCHMARK_TEMPLATE(BM_TryLock, absl::base_internal::SCHEDULE_KERNEL_ONLY)
->UseRealTime()
->Threads(1)
->ThreadPerCpu();
BENCHMARK_TEMPLATE(BM_TryLock,
absl::base_internal::SCHEDULE_COOPERATIVE_AND_KERNEL)
->UseRealTime()
->Threads(1)
->ThreadPerCpu();
} // namespace
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment