2 Star 0 Fork 70

golang-package/carbon

forked from dromara/carbon 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
creator_bench_test.go 5.81 KB
一键复制 编辑 原始数据 按行查看 历史
kuafuRace 提交于 2025-05-10 08:56 +08:00 . test: Optimize test cases
package carbon
import (
"testing"
"time"
)
func BenchmarkCreateFromStdTime(b *testing.B) {
now := time.Now().In(time.Local)
b.Run("without timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromStdTime(now)
}
})
b.Run("with timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromStdTime(now, PRC)
}
})
}
func BenchmarkCreateFromTimestamp(b *testing.B) {
b.Run("without timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromTimestamp(1649735755)
}
})
b.Run("with timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromTimestamp(1649735755, PRC)
}
})
}
func BenchmarkCreateFromTimestampMilli(b *testing.B) {
b.Run("without timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromTimestampMilli(1649735755)
}
})
b.Run("with timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromTimestampMilli(1649735755, PRC)
}
})
}
func BenchmarkCreateFromTimestampMicro(b *testing.B) {
b.Run("without timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromTimestampMicro(1649735755)
}
})
b.Run("with timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromTimestampMicro(1649735755, PRC)
}
})
}
func BenchmarkCreateFromTimestampNano(b *testing.B) {
b.Run("without timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromTimestampNano(1649735755)
}
})
b.Run("with timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromTimestampNano(1649735755, PRC)
}
})
}
func BenchmarkCreateFromDateTime(b *testing.B) {
b.Run("without timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromDateTime(2020, 8, 5, 13, 14, 15)
}
})
b.Run("with timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromDateTime(2020, 8, 5, 13, 14, 15, PRC)
}
})
}
func BenchmarkCreateFromDateTimeMilli(b *testing.B) {
b.Run("without timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromDateTimeMilli(2020, 8, 5, 13, 14, 15, 999)
}
})
b.Run("with timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromDateTimeMilli(2020, 8, 5, 13, 14, 15, 999, PRC)
}
})
}
func BenchmarkCreateFromDateTimeMicro(b *testing.B) {
b.Run("without timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromDateTimeMicro(2020, 8, 5, 13, 14, 15, 999999)
}
})
b.Run("with timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromDateTimeMicro(2020, 8, 5, 13, 14, 15, 999999, PRC)
}
})
}
func BenchmarkCreateFromDateTimeNano(b *testing.B) {
b.Run("without timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromDateTimeNano(2020, 8, 5, 13, 14, 15, 999999999)
}
})
b.Run("with timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromDateTimeNano(2020, 8, 5, 13, 14, 15, 999999999, PRC)
}
})
}
func BenchmarkCreateFromDate(b *testing.B) {
b.Run("without timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromDate(2020, 8, 5)
}
})
b.Run("with timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromDate(2020, 8, 5, PRC)
}
})
}
func BenchmarkCreateFromDateMilli(b *testing.B) {
b.Run("without timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromDateMilli(2020, 8, 5, 999)
}
})
b.Run("with timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromDateMilli(2020, 8, 5, 999, PRC)
}
})
}
func BenchmarkCreateFromDateMicro(b *testing.B) {
b.Run("without timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromDateMicro(2020, 8, 5, 999999)
}
})
b.Run("with timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromDateMicro(2020, 8, 5, 999999, PRC)
}
})
}
func BenchmarkCreateFromDateNano(b *testing.B) {
b.Run("without timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromDateNano(2020, 8, 5, 999999999)
}
})
b.Run("with timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromDateNano(2020, 8, 5, 999999999, PRC)
}
})
}
func BenchmarkCreateFromTime(b *testing.B) {
b.Run("without timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromTime(13, 14, 15)
}
})
b.Run("with timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromTime(13, 14, 15, PRC)
}
})
}
func BenchmarkCreateFromTimeMilli(b *testing.B) {
b.Run("without timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromTimeMilli(13, 14, 15, 999)
}
})
b.Run("with timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromTimeMilli(13, 14, 15, 999, PRC)
}
})
}
func BenchmarkCreateFromTimeMicro(b *testing.B) {
b.Run("without timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromTimeMicro(13, 14, 15, 999999)
}
})
b.Run("with timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromTimeMicro(13, 14, 15, 999999, PRC)
}
})
}
func BenchmarkCreateFromTimeNano(b *testing.B) {
b.Run("without timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromTimeNano(13, 14, 15, 999999999)
}
})
b.Run("with timezone", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
CreateFromTimeNano(13, 14, 15, 999999999, PRC)
}
})
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/golang-package/carbon.git
git@gitee.com:golang-package/carbon.git
golang-package
carbon
carbon
master

搜索帮助