civil_time_benchmark.cc
Go to the documentation of this file.
00001 // Copyright 2018 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/time/civil_time.h"
00016 
00017 #include <numeric>
00018 #include <vector>
00019 
00020 #include "absl/hash/hash.h"
00021 #include "benchmark/benchmark.h"
00022 
00023 namespace {
00024 
00025 // Run on (12 X 3492 MHz CPUs); 2018-11-05T13:44:29.814239103-08:00
00026 // CPU: Intel Haswell with HyperThreading (6 cores) dL1:32KB dL2:256KB dL3:15MB
00027 // Benchmark                 Time(ns)        CPU(ns)     Iterations
00028 // ----------------------------------------------------------------
00029 // BM_Difference_Days              14.5           14.5     48531105
00030 // BM_Step_Days                    12.6           12.6     54876006
00031 // BM_Format                      587            587        1000000
00032 // BM_Parse                       692            692        1000000
00033 // BM_RoundTripFormatParse       1309           1309         532075
00034 // BM_CivilYearAbslHash             0.710          0.710  976400000
00035 // BM_CivilMonthAbslHash            1.13           1.13   619500000
00036 // BM_CivilDayAbslHash              1.70           1.70   426000000
00037 // BM_CivilHourAbslHash             2.45           2.45   287600000
00038 // BM_CivilMinuteAbslHash           3.21           3.21   226200000
00039 // BM_CivilSecondAbslHash           4.10           4.10   171800000
00040 
00041 void BM_Difference_Days(benchmark::State& state) {
00042   const absl::CivilDay c(2014, 8, 22);
00043   const absl::CivilDay epoch(1970, 1, 1);
00044   while (state.KeepRunning()) {
00045     const absl::civil_diff_t n = c - epoch;
00046     benchmark::DoNotOptimize(n);
00047   }
00048 }
00049 BENCHMARK(BM_Difference_Days);
00050 
00051 void BM_Step_Days(benchmark::State& state) {
00052   const absl::CivilDay kStart(2014, 8, 22);
00053   absl::CivilDay c = kStart;
00054   while (state.KeepRunning()) {
00055     benchmark::DoNotOptimize(++c);
00056   }
00057 }
00058 BENCHMARK(BM_Step_Days);
00059 
00060 void BM_Format(benchmark::State& state) {
00061   const absl::CivilSecond c(2014, 1, 2, 3, 4, 5);
00062   while (state.KeepRunning()) {
00063     const std::string s = absl::FormatCivilTime(c);
00064     benchmark::DoNotOptimize(s);
00065   }
00066 }
00067 BENCHMARK(BM_Format);
00068 
00069 template <typename T>
00070 void BM_CivilTimeAbslHash(benchmark::State& state) {
00071   const int kSize = 100000;
00072   std::vector<T> civil_times(kSize);
00073   std::iota(civil_times.begin(), civil_times.end(), T(2018));
00074 
00075   absl::Hash<T> absl_hasher;
00076   while (state.KeepRunningBatch(kSize)) {
00077     for (const T civil_time : civil_times) {
00078       benchmark::DoNotOptimize(absl_hasher(civil_time));
00079     }
00080   }
00081 }
00082 void BM_CivilYearAbslHash(benchmark::State& state) {
00083   BM_CivilTimeAbslHash<absl::CivilYear>(state);
00084 }
00085 void BM_CivilMonthAbslHash(benchmark::State& state) {
00086   BM_CivilTimeAbslHash<absl::CivilMonth>(state);
00087 }
00088 void BM_CivilDayAbslHash(benchmark::State& state) {
00089   BM_CivilTimeAbslHash<absl::CivilDay>(state);
00090 }
00091 void BM_CivilHourAbslHash(benchmark::State& state) {
00092   BM_CivilTimeAbslHash<absl::CivilHour>(state);
00093 }
00094 void BM_CivilMinuteAbslHash(benchmark::State& state) {
00095   BM_CivilTimeAbslHash<absl::CivilMinute>(state);
00096 }
00097 void BM_CivilSecondAbslHash(benchmark::State& state) {
00098   BM_CivilTimeAbslHash<absl::CivilSecond>(state);
00099 }
00100 BENCHMARK(BM_CivilYearAbslHash);
00101 BENCHMARK(BM_CivilMonthAbslHash);
00102 BENCHMARK(BM_CivilDayAbslHash);
00103 BENCHMARK(BM_CivilHourAbslHash);
00104 BENCHMARK(BM_CivilMinuteAbslHash);
00105 BENCHMARK(BM_CivilSecondAbslHash);
00106 
00107 }  // namespace


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