diff options
Diffstat (limited to 'absl/strings')
-rw-r--r-- | absl/strings/charconv.cc | 1 | ||||
-rw-r--r-- | absl/strings/string_view_benchmark.cc | 34 |
2 files changed, 34 insertions, 1 deletions
diff --git a/absl/strings/charconv.cc b/absl/strings/charconv.cc index d9bc2dd20828..bdba768dcd6c 100644 --- a/absl/strings/charconv.cc +++ b/absl/strings/charconv.cc @@ -673,7 +673,6 @@ from_chars_result FromCharsImpl(const char* first, const char* last, EncodeResult(calculated, negative, &result, &value); return result; } - return result; } } // namespace diff --git a/absl/strings/string_view_benchmark.cc b/absl/strings/string_view_benchmark.cc index f2e4214c5110..0d74e23e2fc9 100644 --- a/absl/strings/string_view_benchmark.cc +++ b/absl/strings/string_view_benchmark.cc @@ -160,11 +160,45 @@ void BM_CompareSame(benchmark::State& state) { absl::string_view b = y; for (auto _ : state) { + benchmark::DoNotOptimize(a); + benchmark::DoNotOptimize(b); benchmark::DoNotOptimize(a.compare(b)); } } BENCHMARK(BM_CompareSame)->DenseRange(0, 3)->Range(4, 1 << 10); +void BM_CompareFirstOneLess(benchmark::State& state) { + const int len = state.range(0); + std::string x(len, 'a'); + std::string y = x; + y.back() = 'b'; + absl::string_view a = x; + absl::string_view b = y; + + for (auto _ : state) { + benchmark::DoNotOptimize(a); + benchmark::DoNotOptimize(b); + benchmark::DoNotOptimize(a.compare(b)); + } +} +BENCHMARK(BM_CompareFirstOneLess)->DenseRange(1, 3)->Range(4, 1 << 10); + +void BM_CompareSecondOneLess(benchmark::State& state) { + const int len = state.range(0); + std::string x(len, 'a'); + std::string y = x; + x.back() = 'b'; + absl::string_view a = x; + absl::string_view b = y; + + for (auto _ : state) { + benchmark::DoNotOptimize(a); + benchmark::DoNotOptimize(b); + benchmark::DoNotOptimize(a.compare(b)); + } +} +BENCHMARK(BM_CompareSecondOneLess)->DenseRange(1, 3)->Range(4, 1 << 10); + void BM_find_string_view_len_one(benchmark::State& state) { std::string haystack(state.range(0), '0'); absl::string_view s(haystack); |