fixed_array_benchmark.cc
Go to the documentation of this file.
00001 // Copyright 2017 The Abseil Authors.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //      https://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
00014 
00015 #include "absl/container/fixed_array.h"
00016 
00017 #include <stddef.h>
00018 #include <string>
00019 
00020 #include "benchmark/benchmark.h"
00021 
00022 namespace {
00023 
00024 // For benchmarking -- simple class with constructor and destructor that
00025 // set an int to a constant..
00026 class SimpleClass {
00027  public:
00028   SimpleClass() : i(3) { }
00029   ~SimpleClass() { i = 0; }
00030  private:
00031   int i;
00032 };
00033 
00034 template <typename C, size_t stack_size>
00035 void BM_FixedArray(benchmark::State& state) {
00036   const int size = state.range(0);
00037   for (auto _ : state) {
00038     absl::FixedArray<C, stack_size> fa(size);
00039     benchmark::DoNotOptimize(fa.data());
00040   }
00041 }
00042 BENCHMARK_TEMPLATE(BM_FixedArray, char, absl::kFixedArrayUseDefault)
00043     ->Range(0, 1 << 16);
00044 BENCHMARK_TEMPLATE(BM_FixedArray, char, 0)->Range(0, 1 << 16);
00045 BENCHMARK_TEMPLATE(BM_FixedArray, char, 1)->Range(0, 1 << 16);
00046 BENCHMARK_TEMPLATE(BM_FixedArray, char, 16)->Range(0, 1 << 16);
00047 BENCHMARK_TEMPLATE(BM_FixedArray, char, 256)->Range(0, 1 << 16);
00048 BENCHMARK_TEMPLATE(BM_FixedArray, char, 65536)->Range(0, 1 << 16);
00049 
00050 BENCHMARK_TEMPLATE(BM_FixedArray, SimpleClass, absl::kFixedArrayUseDefault)
00051     ->Range(0, 1 << 16);
00052 BENCHMARK_TEMPLATE(BM_FixedArray, SimpleClass, 0)->Range(0, 1 << 16);
00053 BENCHMARK_TEMPLATE(BM_FixedArray, SimpleClass, 1)->Range(0, 1 << 16);
00054 BENCHMARK_TEMPLATE(BM_FixedArray, SimpleClass, 16)->Range(0, 1 << 16);
00055 BENCHMARK_TEMPLATE(BM_FixedArray, SimpleClass, 256)->Range(0, 1 << 16);
00056 BENCHMARK_TEMPLATE(BM_FixedArray, SimpleClass, 65536)->Range(0, 1 << 16);
00057 
00058 BENCHMARK_TEMPLATE(BM_FixedArray, std::string, absl::kFixedArrayUseDefault)
00059     ->Range(0, 1 << 16);
00060 BENCHMARK_TEMPLATE(BM_FixedArray, std::string, 0)->Range(0, 1 << 16);
00061 BENCHMARK_TEMPLATE(BM_FixedArray, std::string, 1)->Range(0, 1 << 16);
00062 BENCHMARK_TEMPLATE(BM_FixedArray, std::string, 16)->Range(0, 1 << 16);
00063 BENCHMARK_TEMPLATE(BM_FixedArray, std::string, 256)->Range(0, 1 << 16);
00064 BENCHMARK_TEMPLATE(BM_FixedArray, std::string, 65536)->Range(0, 1 << 16);
00065 
00066 }  // namespace


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:14