blob: 053cbd659bef844d8cdaac77dc210c01104d840f [file] [log] [blame]
Stephan T. Lavavejb4ac3b42017-12-13 00:51:31 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruthd2012102019-01-19 10:56:40 +00003// 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
Stephan T. Lavavejb4ac3b42017-12-13 00:51:31 +00006//
7//===----------------------------------------------------------------------===//
8
9#include <memory>
10
Eric Fiselier87038cd2018-01-18 04:23:01 +000011#include "benchmark/benchmark.h"
Stephan T. Lavavejb4ac3b42017-12-13 00:51:31 +000012
13static void BM_SharedPtrCreateDestroy(benchmark::State& st) {
14 while (st.KeepRunning()) {
15 auto sp = std::make_shared<int>(42);
16 benchmark::DoNotOptimize(sp.get());
17 }
18}
19BENCHMARK(BM_SharedPtrCreateDestroy);
20
21static void BM_SharedPtrIncDecRef(benchmark::State& st) {
22 auto sp = std::make_shared<int>(42);
23 benchmark::DoNotOptimize(sp.get());
24 while (st.KeepRunning()) {
25 std::shared_ptr<int> sp2(sp);
26 benchmark::ClobberMemory();
27 }
28}
29BENCHMARK(BM_SharedPtrIncDecRef);
30
31static void BM_WeakPtrIncDecRef(benchmark::State& st) {
32 auto sp = std::make_shared<int>(42);
33 benchmark::DoNotOptimize(sp.get());
34 while (st.KeepRunning()) {
35 std::weak_ptr<int> wp(sp);
36 benchmark::ClobberMemory();
37 }
38}
39BENCHMARK(BM_WeakPtrIncDecRef);
40
Eric Fiselier87038cd2018-01-18 04:23:01 +000041BENCHMARK_MAIN();