summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--absl/synchronization/mutex_benchmark.cc20
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;