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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Russ Cox 2024-05-16 12:59:01 -04:00
parent 9eeb627f60
commit bb88d28bf5
1 changed files with 29 additions and 0 deletions

View 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")