• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03
10 
11 #include <memory>
12 
13 #include "benchmark/benchmark.h"
14 
BM_SharedPtrCreateDestroy(benchmark::State & st)15 static void BM_SharedPtrCreateDestroy(benchmark::State& st) {
16   while (st.KeepRunning()) {
17     auto sp = std::make_shared<int>(42);
18     benchmark::DoNotOptimize(sp.get());
19   }
20 }
21 BENCHMARK(BM_SharedPtrCreateDestroy);
22 
BM_SharedPtrIncDecRef(benchmark::State & st)23 static void BM_SharedPtrIncDecRef(benchmark::State& st) {
24   auto sp = std::make_shared<int>(42);
25   benchmark::DoNotOptimize(sp.get());
26   while (st.KeepRunning()) {
27     std::shared_ptr<int> sp2(sp);
28     benchmark::ClobberMemory();
29   }
30 }
31 BENCHMARK(BM_SharedPtrIncDecRef);
32 
BM_WeakPtrIncDecRef(benchmark::State & st)33 static void BM_WeakPtrIncDecRef(benchmark::State& st) {
34   auto sp = std::make_shared<int>(42);
35   benchmark::DoNotOptimize(sp.get());
36   while (st.KeepRunning()) {
37     std::weak_ptr<int> wp(sp);
38     benchmark::ClobberMemory();
39   }
40 }
41 BENCHMARK(BM_WeakPtrIncDecRef);
42 
43 BENCHMARK_MAIN();
44