spinlock_benchmark.cc
Go to the documentation of this file.
1 // Copyright 2018 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // See also //absl/synchronization:mutex_benchmark for a comparison of SpinLock
16 // and Mutex performance under varying levels of contention.
17 
22 #include "benchmark/benchmark.h"
23 
24 namespace {
25 
26 template <absl::base_internal::SchedulingMode scheduling_mode>
27 static void BM_SpinLock(benchmark::State& state) {
28  // Ensure a ThreadIdentity is installed.
31  nullptr,
32  "GetOrCreateCurrentThreadIdentity() failed");
33 
34  static auto* spinlock = new absl::base_internal::SpinLock(scheduling_mode);
35  for (auto _ : state) {
36  absl::base_internal::SpinLockHolder holder(spinlock);
37  }
38 }
39 
40 BENCHMARK_TEMPLATE(BM_SpinLock,
42  ->UseRealTime()
43  ->Threads(1)
44  ->ThreadPerCpu();
45 
46 BENCHMARK_TEMPLATE(BM_SpinLock,
48  ->UseRealTime()
49  ->Threads(1)
50  ->ThreadPerCpu();
51 
52 } // namespace
#define ABSL_INTERNAL_CHECK(condition, message)
Definition: raw_logging.h:83
base_internal::ThreadIdentity * GetOrCreateCurrentThreadIdentity()


abseil_cpp
Author(s):
autogenerated on Tue Jun 18 2019 19:44:37