abseil-cpp/absl/profiling/internal/periodic_sampler_benchmark.cc
Go to the documentation of this file.
1 // Copyright 2019 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 #include "benchmark/benchmark.h"
17 
18 namespace absl {
20 namespace profiling_internal {
21 namespace {
22 
23 template <typename Sampler>
24 void BM_Sample(Sampler* sampler, benchmark::State& state) {
25  for (auto _ : state) {
26  benchmark::DoNotOptimize(sampler);
27  benchmark::DoNotOptimize(sampler->Sample());
28  }
29 }
30 
31 template <typename Sampler>
32 void BM_SampleMinunumInlined(Sampler* sampler, benchmark::State& state) {
33  for (auto _ : state) {
34  benchmark::DoNotOptimize(sampler);
35  if (ABSL_PREDICT_FALSE(sampler->SubtleMaybeSample())) {
36  benchmark::DoNotOptimize(sampler->SubtleConfirmSample());
37  }
38  }
39 }
40 
41 void BM_PeriodicSampler_TinySample(benchmark::State& state) {
42  struct Tag {};
43  PeriodicSampler<Tag, 10> sampler;
44  BM_Sample(&sampler, state);
45 }
46 BENCHMARK(BM_PeriodicSampler_TinySample);
47 
48 void BM_PeriodicSampler_ShortSample(benchmark::State& state) {
49  struct Tag {};
50  PeriodicSampler<Tag, 1024> sampler;
51  BM_Sample(&sampler, state);
52 }
53 BENCHMARK(BM_PeriodicSampler_ShortSample);
54 
55 void BM_PeriodicSampler_LongSample(benchmark::State& state) {
56  struct Tag {};
57  PeriodicSampler<Tag, 1024 * 1024> sampler;
58  BM_Sample(&sampler, state);
59 }
60 BENCHMARK(BM_PeriodicSampler_LongSample);
61 
62 void BM_PeriodicSampler_LongSampleMinunumInlined(benchmark::State& state) {
63  struct Tag {};
64  PeriodicSampler<Tag, 1024 * 1024> sampler;
65  BM_SampleMinunumInlined(&sampler, state);
66 }
67 BENCHMARK(BM_PeriodicSampler_LongSampleMinunumInlined);
68 
69 void BM_PeriodicSampler_Disabled(benchmark::State& state) {
70  struct Tag {};
71  PeriodicSampler<Tag, 0> sampler;
72  BM_Sample(&sampler, state);
73 }
74 BENCHMARK(BM_PeriodicSampler_Disabled);
75 
76 } // namespace
77 } // namespace profiling_internal
79 } // namespace absl
ABSL_PREDICT_FALSE
#define ABSL_PREDICT_FALSE(x)
Definition: abseil-cpp/absl/base/optimization.h:180
benchmark::DoNotOptimize
BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const &value)
Definition: benchmark/include/benchmark/benchmark.h:375
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition: third_party/abseil-cpp/absl/base/config.h:171
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition: third_party/abseil-cpp/absl/base/config.h:170
gmock_output_test._
_
Definition: bloaty/third_party/googletest/googlemock/test/gmock_output_test.py:175
opencensus.proto.stats.v1.stats_pb2.Tag
Tag
Definition: stats_pb2.py:431
periodic_sampler.h
benchmark::State
Definition: benchmark/include/benchmark/benchmark.h:503
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
BENCHMARK
#define BENCHMARK(n)
Definition: benchmark/include/benchmark/benchmark.h:1170


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:42