diff options
author | 2023-09-20 09:40:54 -0700 | |
---|---|---|
committer | 2023-09-20 09:41:38 -0700 | |
commit | adcaae433fe10da72bc4f8b61eaf559604b81d03 (patch) | |
tree | 11e80b2fd62889a2888a0323d194b3cae360a4f2 | |
parent | 28549d18f7190c59fa5b9eaf4530e15f3f0d521f (diff) |
absl: add Mutex::[Reader]TryLock benchmark
PiperOrigin-RevId: 566991965
Change-Id: I6c4d64de79d303e69b18330bda04fdc84d40893d
-rw-r--r-- | absl/synchronization/mutex_benchmark.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/absl/synchronization/mutex_benchmark.cc b/absl/synchronization/mutex_benchmark.cc index 0af56d9e..c3f54764 100644 --- a/absl/synchronization/mutex_benchmark.cc +++ b/absl/synchronization/mutex_benchmark.cc @@ -42,6 +42,26 @@ void BM_ReaderLock(benchmark::State& state) { } BENCHMARK(BM_ReaderLock)->UseRealTime()->Threads(1)->ThreadPerCpu(); +void BM_TryLock(benchmark::State& state) { + absl::Mutex mu; + for (auto _ : state) { + if (mu.TryLock()) { + mu.Unlock(); + } + } +} +BENCHMARK(BM_TryLock); + +void BM_ReaderTryLock(benchmark::State& state) { + static absl::Mutex* mu = new absl::Mutex; + for (auto _ : state) { + if (mu->ReaderTryLock()) { + mu->ReaderUnlock(); + } + } +} +BENCHMARK(BM_ReaderTryLock)->UseRealTime()->Threads(1)->ThreadPerCpu(); + static void DelayNs(int64_t ns, int* data) { int64_t end = absl::base_internal::CycleClock::Now() + ns * absl::base_internal::CycleClock::Frequency() / 1e9; |