2 Star 0 Fork 70

golang-package/carbon

forked from dromara/carbon 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
type_bench_test.go 4.38 KB
一键复制 编辑 原始数据 按行查看 历史
package carbon
import (
"encoding/json"
"testing"
)
func BenchmarkCarbonType_Scan(b *testing.B) {
c := Now()
b.ResetTimer()
for n := 0; n < b.N; n++ {
_ = c.Scan(c)
}
}
func BenchmarkCarbonType_Value(b *testing.B) {
c := Now()
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, _ = c.Value()
}
}
func BenchmarkCarbonType_MarshalJSON(b *testing.B) {
var model carbonTypeModel
model.Carbon1 = *Parse("2020-08-05 13:14:15.999999999")
model.Carbon2 = Parse("2020-08-05 13:14:15.999999999")
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, _ = json.Marshal(&model)
}
}
func BenchmarkCarbonType_UnmarshalJSON(b *testing.B) {
var model carbonTypeModel
value := `{"carbon1":"2020-08-05 13:14:15","carbon2":"2020-08-05 13:14:15"}`
b.ResetTimer()
for n := 0; n < b.N; n++ {
_ = json.Unmarshal([]byte(value), &model)
}
}
func BenchmarkCarbonType_String(b *testing.B) {
c := Now()
b.ResetTimer()
for n := 0; n < b.N; n++ {
_ = c.String()
}
}
func BenchmarkBuiltinType_Scan(b *testing.B) {
t := NewDateTime(Now())
b.ResetTimer()
for n := 0; n < b.N; n++ {
_ = t.Scan(Now())
}
}
func BenchmarkBuiltinType_Value(b *testing.B) {
t := NewDateTime(Now())
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, _ = t.Value()
}
}
func BenchmarkBuiltinType_MarshalJSON(b *testing.B) {
var model builtinTypeModel
c := Parse("2020-08-05 13:14:15.999999999")
model.Date = *NewDate(c)
model.DateMilli = *NewDateMilli(c)
model.DateMicro = *NewDateMicro(c)
model.DateNano = *NewDateNano(c)
model.Time = *NewTime(c)
model.TimeMilli = *NewTimeMilli(c)
model.TimeMicro = *NewTimeMicro(c)
model.TimeNano = *NewTimeNano(c)
model.DateTime = *NewDateTime(c)
model.DateTimeMilli = *NewDateTimeMilli(c)
model.DateTimeMicro = *NewDateTimeMicro(c)
model.DateTimeNano = *NewDateTimeNano(c)
model.Timestamp = *NewTimestamp(c)
model.TimestampMilli = *NewTimestampMilli(c)
model.TimestampMicro = *NewTimestampMicro(c)
model.TimestampNano = *NewTimestampNano(c)
model.CreatedAt = NewDateTime(c)
model.UpdatedAt = NewDateTime(c)
model.DeletedAt = NewTimestamp(c)
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, _ = json.Marshal(&model)
}
}
func BenchmarkBuiltinType_UnmarshalJSON(b *testing.B) {
var model builtinTypeModel
value := `{"date":"2020-08-05","date_milli":"2020-08-05.999","date_micro":"2020-08-05.999999","date_nano":"2020-08-05.999999999","time":"13:14:15","time_milli":"13:14:15.999","time_micro":"13:14:15.999999","time_nano":"13:14:15.999999999","date_time":"2020-08-05 13:14:15","date_time_milli":"2020-08-05 13:14:15.999","date_time_micro":"2020-08-05 13:14:15.999999","date_time_nano":"2020-08-05 13:14:15.999999999","created_at":"2020-08-05 13:14:15","updated_at":"2020-08-05 13:14:15","timestamp":1596633255,"timestamp_milli":1596633255999,"timestamp_micro":1596633255999999,"timestamp_nano":1596633255999999999,"deleted_at":1596633255}`
b.ResetTimer()
for n := 0; n < b.N; n++ {
_ = json.Unmarshal([]byte(value), &model)
}
}
func BenchmarkBuiltinType_String(b *testing.B) {
t := NewDateTime(Now())
b.ResetTimer()
for n := 0; n < b.N; n++ {
_ = t.String()
}
}
func BenchmarkCustomerType_Scan(b *testing.B) {
t := NewFormatType[iso8601Type](Parse("2020-08-05"))
b.ResetTimer()
for n := 0; n < b.N; n++ {
_ = t.Scan(Now())
}
}
func BenchmarkCustomerType_Value(b *testing.B) {
t := NewFormatType[iso8601Type](Parse("2020-08-05"))
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, _ = t.Value()
}
}
func BenchmarkCustomerType_MarshalJSON(b *testing.B) {
var model CustomerTypeModel
c := Parse("2020-08-05 13:14:15.999999999")
model.Customer1 = *NewLayoutType[rfc3339Type](c)
model.Customer2 = *NewLayoutType[w3cType](c)
model.Customer3 = *NewFormatType[iso8601Type](c)
model.Customer4 = *NewFormatType[rssType](c)
model.CreatedAt = NewFormatType[iso8601Type](c)
model.UpdatedAt = NewLayoutType[rfc3339Type](c)
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, _ = json.Marshal(&model)
}
}
func BenchmarkCustomerType_UnmarshalJSON(b *testing.B) {
var model CustomerTypeModel
value := `{"customer1":"2020-08-05T13:14:15+00:00","customer2":"2020-08-05T13:14:15Z","created_at":"2020-08-05T13:14:15+00:00","updated_at":"2020-08-05T13:14:15Z"}`
b.ResetTimer()
for n := 0; n < b.N; n++ {
_ = json.Unmarshal([]byte(value), &model)
}
}
func BenchmarkCustomerType_String(b *testing.B) {
t := NewFormatType[iso8601Type](Parse("2020-08-05"))
b.ResetTimer()
for n := 0; n < b.N; n++ {
_ = t.String()
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/golang-package/carbon.git
git@gitee.com:golang-package/carbon.git
golang-package
carbon
carbon
master

搜索帮助