fixed_array_benchmark.cc
Go to the documentation of this file.
1 // Copyright 2017 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 
17 #include <stddef.h>
18 #include <string>
19 
20 #include "benchmark/benchmark.h"
21 
22 namespace {
23 
24 // For benchmarking -- simple class with constructor and destructor that
25 // set an int to a constant..
26 class SimpleClass {
27  public:
28  SimpleClass() : i(3) { }
29  ~SimpleClass() { i = 0; }
30  private:
31  int i;
32 };
33 
34 template <typename C, size_t stack_size>
35 void BM_FixedArray(benchmark::State& state) {
36  const int size = state.range(0);
37  for (auto _ : state) {
39  benchmark::DoNotOptimize(fa.data());
40  }
41 }
42 BENCHMARK_TEMPLATE(BM_FixedArray, char, absl::kFixedArrayUseDefault)
43  ->Range(0, 1 << 16);
44 BENCHMARK_TEMPLATE(BM_FixedArray, char, 0)->Range(0, 1 << 16);
45 BENCHMARK_TEMPLATE(BM_FixedArray, char, 1)->Range(0, 1 << 16);
46 BENCHMARK_TEMPLATE(BM_FixedArray, char, 16)->Range(0, 1 << 16);
47 BENCHMARK_TEMPLATE(BM_FixedArray, char, 256)->Range(0, 1 << 16);
48 BENCHMARK_TEMPLATE(BM_FixedArray, char, 65536)->Range(0, 1 << 16);
49 
50 BENCHMARK_TEMPLATE(BM_FixedArray, SimpleClass, absl::kFixedArrayUseDefault)
51  ->Range(0, 1 << 16);
52 BENCHMARK_TEMPLATE(BM_FixedArray, SimpleClass, 0)->Range(0, 1 << 16);
53 BENCHMARK_TEMPLATE(BM_FixedArray, SimpleClass, 1)->Range(0, 1 << 16);
54 BENCHMARK_TEMPLATE(BM_FixedArray, SimpleClass, 16)->Range(0, 1 << 16);
55 BENCHMARK_TEMPLATE(BM_FixedArray, SimpleClass, 256)->Range(0, 1 << 16);
56 BENCHMARK_TEMPLATE(BM_FixedArray, SimpleClass, 65536)->Range(0, 1 << 16);
57 
58 BENCHMARK_TEMPLATE(BM_FixedArray, std::string, absl::kFixedArrayUseDefault)
59  ->Range(0, 1 << 16);
60 BENCHMARK_TEMPLATE(BM_FixedArray, std::string, 0)->Range(0, 1 << 16);
61 BENCHMARK_TEMPLATE(BM_FixedArray, std::string, 1)->Range(0, 1 << 16);
62 BENCHMARK_TEMPLATE(BM_FixedArray, std::string, 16)->Range(0, 1 << 16);
63 BENCHMARK_TEMPLATE(BM_FixedArray, std::string, 256)->Range(0, 1 << 16);
64 BENCHMARK_TEMPLATE(BM_FixedArray, std::string, 65536)->Range(0, 1 << 16);
65 
66 } // namespace
static constexpr auto kFixedArrayUseDefault
Definition: fixed_array.h:55
uintptr_t size


abseil_cpp
Author(s):
autogenerated on Mon Feb 28 2022 21:31:18