brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 445f469 Raw
44 lines · cpp
1//===----------------------------------------------------------------------===//2//3// 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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++0310 11#include <memory>12 13#include "benchmark/benchmark.h"14 15static void BM_SharedPtrCreateDestroy(benchmark::State& st) {16  while (st.KeepRunning()) {17    auto sp = std::make_shared<int>(42);18    benchmark::DoNotOptimize(sp.get());19  }20}21BENCHMARK(BM_SharedPtrCreateDestroy);22 23static void BM_SharedPtrIncDecRef(benchmark::State& st) {24  auto sp = std::make_shared<int>(42);25  benchmark::DoNotOptimize(sp.get());26  while (st.KeepRunning()) {27    std::shared_ptr<int> sp2(sp);28    benchmark::ClobberMemory();29  }30}31BENCHMARK(BM_SharedPtrIncDecRef);32 33static void BM_WeakPtrIncDecRef(benchmark::State& st) {34  auto sp = std::make_shared<int>(42);35  benchmark::DoNotOptimize(sp.get());36  while (st.KeepRunning()) {37    std::weak_ptr<int> wp(sp);38    benchmark::ClobberMemory();39  }40}41BENCHMARK(BM_WeakPtrIncDecRef);42 43BENCHMARK_MAIN();44