Skip to content

Commit

Permalink
Add local vs UTC Timestamp(Time) benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Sep 10, 2023
1 parent 8bff1ec commit 461ae4e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions ulid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,10 +834,23 @@ func BenchmarkNow(b *testing.B) {

func BenchmarkTimestamp(b *testing.B) {
now := time.Now()
b.SetBytes(8)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = ulid.Timestamp(now)
for _, tc := range []struct {
name string
tsfunc func() time.Time
}{
{"WithLocal", func() time.Time { return now }},
{"WithUTC", func() time.Time { return now.UTC() }}, //nolint:gocritic // keep lambda for fair comparison
} {
tc := tc
b.Run(tc.name, func(b *testing.B) {
b.StopTimer()
b.ResetTimer()
b.SetBytes(8)
b.StartTimer()
for i := 0; i < b.N; i++ {
_ = ulid.Timestamp(tc.tsfunc())
}
})
}
}

Expand Down

0 comments on commit 461ae4e

Please sign in to comment.