Skip to content

Instantly share code, notes, and snippets.

@hamakn
Created Aug 20, 2020
Embed
What would you like to do?
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