Skip to content

Commit

Permalink
Add local vs UTC Timestamp(Time) benchmark
Browse files Browse the repository at this point in the history
Co-authored-by: Peter Bourgon <[email protected]>
  • Loading branch information
scop and peterbourgon committed Sep 13, 2023
1 parent 544928b commit 4147f3e
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions ulid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,10 +834,21 @@ 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.SetBytes(8)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = ulid.Timestamp(tc.tsfunc())
}
})
}
}

Expand Down

0 comments on commit 4147f3e

Please sign in to comment.