Skip to content

Commit 298fd26

Browse files
gribozavrcopybara-github
authored andcommitted
Fix warnings:
* 'DoNotOptimize<T>' is deprecated: The const-ref version of this method can permit undesired compiler optimizations in benchmarks * missing #include <string> for 'std::string' PiperOrigin-RevId: 554936149 Change-Id: Iaf06cd9b9b0762e3a514b7e1cfe4a4fd6df24083
1 parent a3c403f commit 298fd26

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

absl/time/civil_time_benchmark.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
#include "absl/time/civil_time.h"
1616

17+
#include <cstddef>
1718
#include <numeric>
19+
#include <string>
1820
#include <vector>
1921

2022
#include "absl/hash/hash.h"
@@ -42,7 +44,7 @@ void BM_Difference_Days(benchmark::State& state) {
4244
const absl::CivilDay c(2014, 8, 22);
4345
const absl::CivilDay epoch(1970, 1, 1);
4446
while (state.KeepRunning()) {
45-
const absl::civil_diff_t n = c - epoch;
47+
absl::civil_diff_t n = c - epoch;
4648
benchmark::DoNotOptimize(n);
4749
}
4850
}
@@ -60,7 +62,7 @@ BENCHMARK(BM_Step_Days);
6062
void BM_Format(benchmark::State& state) {
6163
const absl::CivilSecond c(2014, 1, 2, 3, 4, 5);
6264
while (state.KeepRunning()) {
63-
const std::string s = absl::FormatCivilTime(c);
65+
std::string s = absl::FormatCivilTime(c);
6466
benchmark::DoNotOptimize(s);
6567
}
6668
}
@@ -70,7 +72,7 @@ void BM_Parse(benchmark::State& state) {
7072
const std::string f = "2014-01-02T03:04:05";
7173
absl::CivilSecond c;
7274
while (state.KeepRunning()) {
73-
const bool b = absl::ParseCivilTime(f, &c);
75+
bool b = absl::ParseCivilTime(f, &c);
7476
benchmark::DoNotOptimize(b);
7577
}
7678
}
@@ -80,7 +82,7 @@ void BM_RoundTripFormatParse(benchmark::State& state) {
8082
const absl::CivilSecond c(2014, 1, 2, 3, 4, 5);
8183
absl::CivilSecond out;
8284
while (state.KeepRunning()) {
83-
const bool b = absl::ParseCivilTime(absl::FormatCivilTime(c), &out);
85+
bool b = absl::ParseCivilTime(absl::FormatCivilTime(c), &out);
8486
benchmark::DoNotOptimize(b);
8587
}
8688
}
@@ -95,7 +97,8 @@ void BM_CivilTimeAbslHash(benchmark::State& state) {
9597
absl::Hash<T> absl_hasher;
9698
while (state.KeepRunningBatch(kSize)) {
9799
for (const T civil_time : civil_times) {
98-
benchmark::DoNotOptimize(absl_hasher(civil_time));
100+
size_t hash = absl_hasher(civil_time);
101+
benchmark::DoNotOptimize(hash);
99102
}
100103
}
101104
}

0 commit comments

Comments
 (0)