summaryrefslogtreecommitdiff
path: root/absl/time
diff options
context:
space:
mode:
Diffstat (limited to 'absl/time')
-rw-r--r--absl/time/BUILD.bazel1
-rw-r--r--absl/time/civil_time_benchmark.cc64
-rw-r--r--absl/time/internal/cctz/BUILD.bazel2
-rw-r--r--absl/time/time.h3
4 files changed, 63 insertions, 7 deletions
diff --git a/absl/time/BUILD.bazel b/absl/time/BUILD.bazel
index 969ddd2e..4d9c01c4 100644
--- a/absl/time/BUILD.bazel
+++ b/absl/time/BUILD.bazel
@@ -110,6 +110,7 @@ cc_test(
":test_util",
":time",
"//absl/base",
+ "//absl/hash",
"@com_github_google_benchmark//:benchmark_main",
],
)
diff --git a/absl/time/civil_time_benchmark.cc b/absl/time/civil_time_benchmark.cc
index 567c2a33..f30f636d 100644
--- a/absl/time/civil_time_benchmark.cc
+++ b/absl/time/civil_time_benchmark.cc
@@ -14,17 +14,29 @@
#include "absl/time/civil_time.h"
+#include <numeric>
+#include <vector>
+
+#include "absl/hash/hash.h"
#include "benchmark/benchmark.h"
namespace {
-// Benchmark Time(ns) CPU(ns) Iterations
-// -------------------------------------------------------------------------
-// BM_Difference_Days 20 20 34542508
-// BM_Step_Days 15 15 48098146
-// BM_Format 688 687 1019803
-// BM_Parse 921 920 762788
-// BM_RoundTripFormatParse 1766 1764 396092
+// Run on (12 X 3492 MHz CPUs); 2018-11-05T13:44:29.814239103-08:00
+// CPU: Intel Haswell with HyperThreading (6 cores) dL1:32KB dL2:256KB dL3:15MB
+// Benchmark Time(ns) CPU(ns) Iterations
+// ----------------------------------------------------------------
+// BM_Difference_Days 14.5 14.5 48531105
+// BM_Step_Days 12.6 12.6 54876006
+// BM_Format 587 587 1000000
+// BM_Parse 692 692 1000000
+// BM_RoundTripFormatParse 1309 1309 532075
+// BM_CivilYearAbslHash 0.710 0.710 976400000
+// BM_CivilMonthAbslHash 1.13 1.13 619500000
+// BM_CivilDayAbslHash 1.70 1.70 426000000
+// BM_CivilHourAbslHash 2.45 2.45 287600000
+// BM_CivilMinuteAbslHash 3.21 3.21 226200000
+// BM_CivilSecondAbslHash 4.10 4.10 171800000
void BM_Difference_Days(benchmark::State& state) {
const absl::CivilDay c(2014, 8, 22);
@@ -54,4 +66,42 @@ void BM_Format(benchmark::State& state) {
}
BENCHMARK(BM_Format);
+template <typename T>
+void BM_CivilTimeAbslHash(benchmark::State& state) {
+ const int kSize = 100000;
+ std::vector<T> civil_times(kSize);
+ std::iota(civil_times.begin(), civil_times.end(), T(2018));
+
+ absl::Hash<T> absl_hasher;
+ while (state.KeepRunningBatch(kSize)) {
+ for (const T civil_time : civil_times) {
+ benchmark::DoNotOptimize(absl_hasher(civil_time));
+ }
+ }
+}
+void BM_CivilYearAbslHash(benchmark::State& state) {
+ BM_CivilTimeAbslHash<absl::CivilYear>(state);
+}
+void BM_CivilMonthAbslHash(benchmark::State& state) {
+ BM_CivilTimeAbslHash<absl::CivilMonth>(state);
+}
+void BM_CivilDayAbslHash(benchmark::State& state) {
+ BM_CivilTimeAbslHash<absl::CivilDay>(state);
+}
+void BM_CivilHourAbslHash(benchmark::State& state) {
+ BM_CivilTimeAbslHash<absl::CivilHour>(state);
+}
+void BM_CivilMinuteAbslHash(benchmark::State& state) {
+ BM_CivilTimeAbslHash<absl::CivilMinute>(state);
+}
+void BM_CivilSecondAbslHash(benchmark::State& state) {
+ BM_CivilTimeAbslHash<absl::CivilSecond>(state);
+}
+BENCHMARK(BM_CivilYearAbslHash);
+BENCHMARK(BM_CivilMonthAbslHash);
+BENCHMARK(BM_CivilDayAbslHash);
+BENCHMARK(BM_CivilHourAbslHash);
+BENCHMARK(BM_CivilMinuteAbslHash);
+BENCHMARK(BM_CivilSecondAbslHash);
+
} // namespace
diff --git a/absl/time/internal/cctz/BUILD.bazel b/absl/time/internal/cctz/BUILD.bazel
index e913fad3..e2cfe801 100644
--- a/absl/time/internal/cctz/BUILD.bazel
+++ b/absl/time/internal/cctz/BUILD.bazel
@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+package(features = ["-parse_headers"])
+
licenses(["notice"]) # Apache License
### libraries
diff --git a/absl/time/time.h b/absl/time/time.h
index de12e560..3fa9378f 100644
--- a/absl/time/time.h
+++ b/absl/time/time.h
@@ -1336,9 +1336,12 @@ constexpr Duration MakeNormalizedDuration(int64_t sec, int64_t ticks) {
return (ticks < 0) ? MakeDuration(sec - 1, ticks + kTicksPerSecond)
: MakeDuration(sec, ticks);
}
+
// Provide access to the Duration representation.
constexpr int64_t GetRepHi(Duration d) { return d.rep_hi_; }
constexpr uint32_t GetRepLo(Duration d) { return d.rep_lo_; }
+
+// Returns true iff d is positive or negative infinity.
constexpr bool IsInfiniteDuration(Duration d) { return GetRepLo(d) == ~0U; }
// Returns an infinite Duration with the opposite sign.