Skip to content

Instantly share code, notes, and snippets.

@hamakn
Created August 20, 2020 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamakn/15d99c685223a67fe001b61d80afeb35 to your computer and use it in GitHub Desktop.
Save hamakn/15d99c685223a67fe001b61d80afeb35 to your computer and use it in GitHub Desktop.
package main
import (
"testing"
"time"
)
func BenchmarkTimeDate(b *testing.B) {
now := time.Now()
b.ResetTimer()
b.ReportAllocs()
for n := 0; n < b.N; n++ {
now.Date()
}
}
func BenchmarkTimeYearMonthDay(b *testing.B) {
now := time.Now()
b.ResetTimer()
b.ReportAllocs()
for n := 0; n < b.N; n++ {
now.Year()
now.Month()
now.Day()
}
}
% go test -bench . -benchmem --tags=parallel [~/dev/src/github.com/kouzoh/merpay-api:2:52]
goos: darwin
goarch: amd64
BenchmarkTimeDate-4 45085794 24.1 ns/op 0 B/op 0 allocs/op
BenchmarkTimeYearMonthDay-4 19379534 62.1 ns/op 0 B/op 0 allocs/op
PASS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment