Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <cstddef>
00015 #include <string>
00016
00017 #include "absl/time/internal/test_util.h"
00018 #include "absl/time/time.h"
00019 #include "benchmark/benchmark.h"
00020
00021 namespace {
00022
00023 namespace {
00024 const char* const kFormats[] = {
00025 absl::RFC1123_full,
00026 absl::RFC1123_no_wday,
00027 absl::RFC3339_full,
00028 absl::RFC3339_sec,
00029 "%Y-%m-%dT%H:%M:%S",
00030 "%Y-%m-%d",
00031 };
00032 const int kNumFormats = sizeof(kFormats) / sizeof(kFormats[0]);
00033 }
00034
00035 void BM_Format_FormatTime(benchmark::State& state) {
00036 const std::string fmt = kFormats[state.range(0)];
00037 state.SetLabel(fmt);
00038 const absl::TimeZone lax =
00039 absl::time_internal::LoadTimeZone("America/Los_Angeles");
00040 const absl::Time t =
00041 absl::FromCivil(absl::CivilSecond(1977, 6, 28, 9, 8, 7), lax) +
00042 absl::Nanoseconds(1);
00043 while (state.KeepRunning()) {
00044 benchmark::DoNotOptimize(absl::FormatTime(fmt, t, lax).length());
00045 }
00046 }
00047 BENCHMARK(BM_Format_FormatTime)->DenseRange(0, kNumFormats - 1);
00048
00049 void BM_Format_ParseTime(benchmark::State& state) {
00050 const std::string fmt = kFormats[state.range(0)];
00051 state.SetLabel(fmt);
00052 const absl::TimeZone lax =
00053 absl::time_internal::LoadTimeZone("America/Los_Angeles");
00054 absl::Time t = absl::FromCivil(absl::CivilSecond(1977, 6, 28, 9, 8, 7), lax) +
00055 absl::Nanoseconds(1);
00056 const std::string when = absl::FormatTime(fmt, t, lax);
00057 std::string err;
00058 while (state.KeepRunning()) {
00059 benchmark::DoNotOptimize(absl::ParseTime(fmt, when, lax, &t, &err));
00060 }
00061 }
00062 BENCHMARK(BM_Format_ParseTime)->DenseRange(0, kNumFormats - 1);
00063
00064 }