1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 #include "benchmark/benchmark.h"
14 static void BM_SharedPtrCreateDestroy(benchmark::State& st) {
15 while (st.KeepRunning()) {
16 auto sp = std::make_shared<int>(42);
17 benchmark::DoNotOptimize(sp.get());
20 BENCHMARK(BM_SharedPtrCreateDestroy);
22 static void BM_SharedPtrIncDecRef(benchmark::State& st) {
23 auto sp = std::make_shared<int>(42);
24 benchmark::DoNotOptimize(sp.get());
25 while (st.KeepRunning()) {
26 std::shared_ptr<int> sp2(sp);
27 benchmark::ClobberMemory();
30 BENCHMARK(BM_SharedPtrIncDecRef);
32 static void BM_WeakPtrIncDecRef(benchmark::State& st) {
33 auto sp = std::make_shared<int>(42);
34 benchmark::DoNotOptimize(sp.get());
35 while (st.KeepRunning()) {
36 std::weak_ptr<int> wp(sp);
37 benchmark::ClobberMemory();
40 BENCHMARK(BM_WeakPtrIncDecRef);