]> Cypherpunks repositories - gostls13.git/commitdiff
time: add a few more benchmarks
authorRuss Cox <rsc@golang.org>
Thu, 16 May 2024 16:59:01 +0000 (12:59 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 23 May 2024 03:13:47 +0000 (03:13 +0000)
Preparation for upcoming optimizations.

For #63844.

Change-Id: I61803dd8b699e51c391614c99ebbd005df5261cc
Reviewed-on: https://go-review.googlesource.com/c/go/+/586256
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/time/time_test.go

index 86335e3796009d361cdfd390b9ded1b0a03c070f..70eb61478480e0f445aa1e6dfd4c959925feccde 100644 (file)
@@ -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")