blob: c984b2ca6665c16081d61d5b01d55d765918bf45 [file] [log] [blame]
Stephan T. Lavavejb4ac3b42017-12-13 00:51:31 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include <memory>
11
Eric Fiselier87038cd2018-01-18 04:23:01 +000012#include "benchmark/benchmark.h"
Stephan T. Lavavejb4ac3b42017-12-13 00:51:31 +000013
14static void BM_SharedPtrCreateDestroy(benchmark::State& st) {
15 while (st.KeepRunning()) {
16 auto sp = std::make_shared<int>(42);
17 benchmark::DoNotOptimize(sp.get());
18 }
19}
20BENCHMARK(BM_SharedPtrCreateDestroy);
21
22static 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();
28 }
29}
30BENCHMARK(BM_SharedPtrIncDecRef);
31
32static 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();
38 }
39}
40BENCHMARK(BM_WeakPtrIncDecRef);
41
Eric Fiselier87038cd2018-01-18 04:23:01 +000042BENCHMARK_MAIN();