2 * Copyright 2016 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <folly/Benchmark.h>
18 #include <folly/SmallLocks.h>
20 BENCHMARK(MicroSpinLockUncontendedBenchmark, iters) {
21 folly::MicroSpinLock lock;
29 BENCHMARK(PicoSpinLockUncontendedBenchmark, iters) {
30 // uint8_t would be more fair, but PicoSpinLock needs at lesat two bytes
31 folly::PicoSpinLock<uint16_t> lock;
39 BENCHMARK(MicroLockUncontendedBenchmark, iters) {
40 folly::MicroLock lock;
48 BENCHMARK(StdMutexUncontendedBenchmark, iters) {
57 virtual void foo() = 0;
58 virtual ~VirtualBase() {}
61 struct VirtualImpl : VirtualBase {
62 virtual void foo() { /* noop */
64 virtual ~VirtualImpl() {}
68 __attribute__((noinline, noclone)) VirtualBase* makeVirtual() {
69 return new VirtualImpl();
72 BENCHMARK(VirtualFunctionCall, iters) {
73 VirtualBase* vb = makeVirtual();
81 int main(int argc, char** argv) {
82 gflags::ParseCommandLineFlags(&argc, &argv, true);
83 folly::runBenchmarks();