llvm-project
41 строка · 1.2 Кб
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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include <memory>
10
11#include "benchmark/benchmark.h"
12
13static void BM_SharedPtrCreateDestroy(benchmark::State& st) {
14while (st.KeepRunning()) {
15auto sp = std::make_shared<int>(42);
16benchmark::DoNotOptimize(sp.get());
17}
18}
19BENCHMARK(BM_SharedPtrCreateDestroy);
20
21static void BM_SharedPtrIncDecRef(benchmark::State& st) {
22auto sp = std::make_shared<int>(42);
23benchmark::DoNotOptimize(sp.get());
24while (st.KeepRunning()) {
25std::shared_ptr<int> sp2(sp);
26benchmark::ClobberMemory();
27}
28}
29BENCHMARK(BM_SharedPtrIncDecRef);
30
31static void BM_WeakPtrIncDecRef(benchmark::State& st) {
32auto sp = std::make_shared<int>(42);
33benchmark::DoNotOptimize(sp.get());
34while (st.KeepRunning()) {
35std::weak_ptr<int> wp(sp);
36benchmark::ClobberMemory();
37}
38}
39BENCHMARK(BM_WeakPtrIncDecRef);
40
41BENCHMARK_MAIN();
42