46 lines
837 B
Go
46 lines
837 B
Go
|
|
package cast_test
|
||
|
|
|
||
|
|
import (
|
||
|
|
"testing"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"apigo.cc/go/cast"
|
||
|
|
)
|
||
|
|
|
||
|
|
func BenchmarkParseTime_RFC3339(b *testing.B) {
|
||
|
|
s := "2023-05-04T12:34:56Z"
|
||
|
|
b.ResetTimer()
|
||
|
|
for i := 0; i < b.N; i++ {
|
||
|
|
_ = cast.ParseTime(s)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func BenchmarkParseTime_Standard(b *testing.B) {
|
||
|
|
s := "2023-05-04 12:34:56"
|
||
|
|
b.ResetTimer()
|
||
|
|
for i := 0; i < b.N; i++ {
|
||
|
|
_ = cast.ParseTime(s)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func BenchmarkParseTime_Numeric(b *testing.B) {
|
||
|
|
s := "20230504123456"
|
||
|
|
b.ResetTimer()
|
||
|
|
for i := 0; i < b.N; i++ {
|
||
|
|
_ = cast.ParseTime(s)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func BenchmarkToJSON_WithTime(b *testing.B) {
|
||
|
|
type User struct {
|
||
|
|
ID int `json:"id"`
|
||
|
|
Name string `json:"name"`
|
||
|
|
CreatedAt time.Time `json:"created_at"`
|
||
|
|
}
|
||
|
|
u := User{ID: 1, Name: "Benchmark User", CreatedAt: time.Now()}
|
||
|
|
b.ResetTimer()
|
||
|
|
for i := 0; i < b.N; i++ {
|
||
|
|
_, _ = cast.ToJSON(u)
|
||
|
|
}
|
||
|
|
}
|