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