Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ add_benchmark(has_single_bit src/has_single_bit.cpp)
add_benchmark(iota src/iota.cpp)
add_benchmark(is_sorted_until src/is_sorted_until.cpp)
add_benchmark(locale_classic src/locale_classic.cpp)
add_benchmark(locate_zone src/locate_zone.cpp)
add_benchmark(minmax_element src/minmax_element.cpp)
add_benchmark(mismatch src/mismatch.cpp)
add_benchmark(move_only_function src/move_only_function.cpp)
Expand Down
19 changes: 19 additions & 0 deletions benchmarks/src/locate_zone.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "benchmark/benchmark.h"
#include <chrono>

void locate_zone(benchmark::State& state) {
auto&& tzdb = std::chrono::get_tzdb();
for (auto _ : state) {
for (std::size_t i = 0; i != tzdb.zones.size(); ++i) {
auto res = tzdb.locate_zone(tzdb.zones[i].name());
benchmark::DoNotOptimize(res);
}
}
}

BENCHMARK(locate_zone);

BENCHMARK_MAIN();
5 changes: 3 additions & 2 deletions stl/inc/chrono
Original file line number Diff line number Diff line change
Expand Up @@ -2105,8 +2105,9 @@ namespace chrono {

template <class _Ty>
_NODISCARD const _Ty* _Locate_zone_impl(const vector<_Ty>& _Vec, string_view _Name) {
const auto _Result = _STD find_if(_Vec.begin(), _Vec.end(), [&](auto& _Tz) { return _Tz.name() == _Name; });
return _Result == _Vec.end() ? nullptr : &*_Result;
const auto _Result = _STD lower_bound(
_Vec.begin(), _Vec.end(), _Name, [](const auto& _Tz, const auto& _Sv) { return _Tz.name() < _Sv; });
return (_Result == _Vec.end() || _Result->name() != _Name) ? nullptr : &*_Result;
}

_EXPORT_STD struct tzdb {
Expand Down