From bb88d28bf5a45563ba49357d9845585ac5f8f768 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 16 May 2024 12:59:01 -0400 Subject: [PATCH] time: add a few more benchmarks Preparation for upcoming optimizations. For #63844. Change-Id: I61803dd8b699e51c391614c99ebbd005df5261cc Reviewed-on: https://go-review.googlesource.com/c/go/+/586256 LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor --- src/time/time_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/time/time_test.go b/src/time/time_test.go index 86335e3796..70eb614784 100644 --- a/src/time/time_test.go +++ b/src/time/time_test.go @@ -1539,6 +1539,13 @@ func BenchmarkSecond(b *testing.B) { } } +func BenchmarkDate(b *testing.B) { + t := Now() + for i := 0; i < b.N; i++ { + _, _, _ = t.Date() + } +} + func BenchmarkYear(b *testing.B) { t := Now() for i := 0; i < b.N; i++ { @@ -1546,6 +1553,20 @@ func BenchmarkYear(b *testing.B) { } } +func BenchmarkYearDay(b *testing.B) { + t := Now() + for i := 0; i < b.N; i++ { + _ = t.YearDay() + } +} + +func BenchmarkMonth(b *testing.B) { + t := Now() + for i := 0; i < b.N; i++ { + _ = t.Month() + } +} + func BenchmarkDay(b *testing.B) { t := Now() for i := 0; i < b.N; i++ { @@ -1567,6 +1588,14 @@ func BenchmarkGoString(b *testing.B) { } } +func BenchmarkDateFunc(b *testing.B) { + var t Time + for range b.N { + t = Date(2020, 8, 22, 11, 27, 43, 123456789, UTC) + } + _ = t +} + func BenchmarkUnmarshalText(b *testing.B) { var t Time in := []byte("2020-08-22T11:27:43.123456789-02:00") -- 2.48.1