Ben Craig | 5753a7d | 2016-08-01 19:56:39 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===//
|
| 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 |
|
| 12 | #include "benchmark/benchmark_api.h"
|
| 13 |
|
| 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());
|
| 18 | }
|
| 19 | }
|
| 20 | BENCHMARK(BM_SharedPtrCreateDestroy);
|
| 21 |
|
| 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();
|
| 28 | }
|
| 29 | }
|
| 30 | BENCHMARK(BM_SharedPtrIncDecRef);
|
| 31 |
|
| 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();
|
| 38 | }
|
| 39 | }
|
| 40 | BENCHMARK(BM_WeakPtrIncDecRef);
|
| 41 |
|
| 42 | BENCHMARK_MAIN()
|