From 298fd26156453f169bfb8eb6df0a12f8c06e82ae Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Tue, 8 Aug 2023 14:07:40 -0700 Subject: Fix warnings: * 'DoNotOptimize' is deprecated: The const-ref version of this method can permit undesired compiler optimizations in benchmarks * missing #include for 'std::string' PiperOrigin-RevId: 554936149 Change-Id: Iaf06cd9b9b0762e3a514b7e1cfe4a4fd6df24083 --- absl/time/civil_time_benchmark.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'absl/time') diff --git a/absl/time/civil_time_benchmark.cc b/absl/time/civil_time_benchmark.cc index f04dbe20..2de0233d 100644 --- a/absl/time/civil_time_benchmark.cc +++ b/absl/time/civil_time_benchmark.cc @@ -14,7 +14,9 @@ #include "absl/time/civil_time.h" +#include #include +#include #include #include "absl/hash/hash.h" @@ -42,7 +44,7 @@ void BM_Difference_Days(benchmark::State& state) { const absl::CivilDay c(2014, 8, 22); const absl::CivilDay epoch(1970, 1, 1); while (state.KeepRunning()) { - const absl::civil_diff_t n = c - epoch; + absl::civil_diff_t n = c - epoch; benchmark::DoNotOptimize(n); } } @@ -60,7 +62,7 @@ BENCHMARK(BM_Step_Days); void BM_Format(benchmark::State& state) { const absl::CivilSecond c(2014, 1, 2, 3, 4, 5); while (state.KeepRunning()) { - const std::string s = absl::FormatCivilTime(c); + std::string s = absl::FormatCivilTime(c); benchmark::DoNotOptimize(s); } } @@ -70,7 +72,7 @@ void BM_Parse(benchmark::State& state) { const std::string f = "2014-01-02T03:04:05"; absl::CivilSecond c; while (state.KeepRunning()) { - const bool b = absl::ParseCivilTime(f, &c); + bool b = absl::ParseCivilTime(f, &c); benchmark::DoNotOptimize(b); } } @@ -80,7 +82,7 @@ void BM_RoundTripFormatParse(benchmark::State& state) { const absl::CivilSecond c(2014, 1, 2, 3, 4, 5); absl::CivilSecond out; while (state.KeepRunning()) { - const bool b = absl::ParseCivilTime(absl::FormatCivilTime(c), &out); + bool b = absl::ParseCivilTime(absl::FormatCivilTime(c), &out); benchmark::DoNotOptimize(b); } } @@ -95,7 +97,8 @@ void BM_CivilTimeAbslHash(benchmark::State& state) { absl::Hash absl_hasher; while (state.KeepRunningBatch(kSize)) { for (const T civil_time : civil_times) { - benchmark::DoNotOptimize(absl_hasher(civil_time)); + size_t hash = absl_hasher(civil_time); + benchmark::DoNotOptimize(hash); } } } -- cgit v1.2.3