abseil-cpp/absl/time/format_benchmark.cc
Go to the documentation of this file.
1 // Copyright 2018 The Abseil Authors.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // https://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 #include <cstddef>
15 #include <string>
16 
17 #include "absl/time/internal/test_util.h"
18 #include "absl/time/time.h"
19 #include "benchmark/benchmark.h"
20 
21 namespace {
22 
23 namespace {
24 const char* const kFormats[] = {
25  absl::RFC1123_full, // 0
27  absl::RFC3339_full, // 2
28  absl::RFC3339_sec, // 3
29  "%Y-%m-%d%ET%H:%M:%S", // 4
30  "%Y-%m-%d", // 5
31 };
32 const int kNumFormats = sizeof(kFormats) / sizeof(kFormats[0]);
33 } // namespace
34 
35 void BM_Format_FormatTime(benchmark::State& state) {
36  const std::string fmt = kFormats[state.range(0)];
37  state.SetLabel(fmt);
38  const absl::TimeZone lax =
39  absl::time_internal::LoadTimeZone("America/Los_Angeles");
40  const absl::Time t =
41  absl::FromCivil(absl::CivilSecond(1977, 6, 28, 9, 8, 7), lax) +
43  while (state.KeepRunning()) {
45  }
46 }
47 BENCHMARK(BM_Format_FormatTime)->DenseRange(0, kNumFormats - 1);
48 
49 void BM_Format_ParseTime(benchmark::State& state) {
50  const std::string fmt = kFormats[state.range(0)];
51  state.SetLabel(fmt);
52  const absl::TimeZone lax =
53  absl::time_internal::LoadTimeZone("America/Los_Angeles");
54  absl::Time t = absl::FromCivil(absl::CivilSecond(1977, 6, 28, 9, 8, 7), lax) +
56  const std::string when = absl::FormatTime(fmt, t, lax);
58  while (state.KeepRunning()) {
60  }
61 }
62 BENCHMARK(BM_Format_ParseTime)->DenseRange(0, kNumFormats - 1);
63 
64 } // namespace
absl::Time
Definition: third_party/abseil-cpp/absl/time/time.h:642
absl::time_internal::cctz::detail::civil_time< time_internal::second_tag >
absl::Nanoseconds
constexpr Duration Nanoseconds(T n)
Definition: third_party/abseil-cpp/absl/time/time.h:407
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
error_ref_leak.err
err
Definition: error_ref_leak.py:35
benchmark::DoNotOptimize
BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const &value)
Definition: benchmark/include/benchmark/benchmark.h:375
absl::FormatTime
std::string FormatTime(absl::string_view format, absl::Time t, absl::TimeZone tz)
Definition: abseil-cpp/absl/time/format.cc:74
absl::ParseTime
bool ParseTime(absl::string_view format, absl::string_view input, absl::Time *time, std::string *err)
Definition: abseil-cpp/absl/time/format.cc:91
absl::RFC3339_full
ABSL_NAMESPACE_BEGIN const ABSL_DLL char RFC3339_full[]
Definition: third_party/abseil-cpp/absl/time/time.h:1261
absl::RFC1123_full
const ABSL_DLL char RFC1123_full[]
Definition: third_party/abseil-cpp/absl/time/time.h:1268
testing::internal::fmt
GTEST_API_ const char * fmt
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1808
absl::str_format_internal::LengthMod::t
@ t
benchmark::State
Definition: benchmark/include/benchmark/benchmark.h:503
absl::FromCivil
Time FromCivil(CivilSecond ct, TimeZone tz)
Definition: third_party/abseil-cpp/absl/time/time.h:1158
absl::RFC3339_sec
const ABSL_DLL char RFC3339_sec[]
Definition: third_party/abseil-cpp/absl/time/time.h:1262
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
absl::time_internal::LoadTimeZone
TimeZone LoadTimeZone(const std::string &name)
Definition: abseil-cpp/absl/time/internal/test_util.cc:32
absl::RFC1123_no_wday
const ABSL_DLL char RFC1123_no_wday[]
Definition: third_party/abseil-cpp/absl/time/time.h:1269
BENCHMARK
#define BENCHMARK(n)
Definition: benchmark/include/benchmark/benchmark.h:1170
length
std::size_t length
Definition: abseil-cpp/absl/time/internal/test_util.cc:57
absl::TimeZone
Definition: third_party/abseil-cpp/absl/time/time.h:912


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:24