Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
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 }