Commit adcaae43 by Dmitry Vyukov Committed by Copybara-Service

absl: add Mutex::[Reader]TryLock benchmark

PiperOrigin-RevId: 566991965
Change-Id: I6c4d64de79d303e69b18330bda04fdc84d40893d
parent 28549d18
...@@ -42,6 +42,26 @@ void BM_ReaderLock(benchmark::State& state) { ...@@ -42,6 +42,26 @@ void BM_ReaderLock(benchmark::State& state) {
} }
BENCHMARK(BM_ReaderLock)->UseRealTime()->Threads(1)->ThreadPerCpu(); 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) { static void DelayNs(int64_t ns, int* data) {
int64_t end = absl::base_internal::CycleClock::Now() + int64_t end = absl::base_internal::CycleClock::Now() +
ns * absl::base_internal::CycleClock::Frequency() / 1e9; ns * absl::base_internal::CycleClock::Frequency() / 1e9;
......
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