2021-01-03 23:37:45 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2018-04-09 17:55:46 +08:00
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
2019-02-02 16:18:25 +08:00
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
2018-04-09 17:55:46 +08:00
|
|
|
|
2019-04-06 22:48:47 +08:00
|
|
|
package gtime_test
|
2018-04-09 17:55:46 +08:00
|
|
|
|
|
|
|
import (
|
2019-04-06 22:48:47 +08:00
|
|
|
"testing"
|
2021-01-03 23:37:45 +08:00
|
|
|
"time"
|
2019-04-06 22:48:47 +08:00
|
|
|
|
2019-07-29 21:01:19 +08:00
|
|
|
"github.com/gogf/gf/os/gtime"
|
2018-04-09 17:55:46 +08:00
|
|
|
)
|
|
|
|
|
2020-05-27 11:26:05 +08:00
|
|
|
func Benchmark_Timestamp(b *testing.B) {
|
2019-04-06 22:48:47 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2020-01-20 14:14:11 +08:00
|
|
|
gtime.Timestamp()
|
2019-04-06 22:48:47 +08:00
|
|
|
}
|
2018-07-04 19:32:51 +08:00
|
|
|
}
|
|
|
|
|
2020-05-27 11:26:05 +08:00
|
|
|
func Benchmark_TimestampMilli(b *testing.B) {
|
2019-04-06 22:48:47 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2020-01-20 14:14:11 +08:00
|
|
|
gtime.TimestampMilli()
|
2019-04-06 22:48:47 +08:00
|
|
|
}
|
2018-07-04 19:32:51 +08:00
|
|
|
}
|
|
|
|
|
2020-05-27 11:26:05 +08:00
|
|
|
func Benchmark_TimestampMicro(b *testing.B) {
|
2019-04-06 22:48:47 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2020-01-20 14:14:11 +08:00
|
|
|
gtime.TimestampMicro()
|
2019-04-06 22:48:47 +08:00
|
|
|
}
|
2018-07-04 19:32:51 +08:00
|
|
|
}
|
|
|
|
|
2020-05-27 11:26:05 +08:00
|
|
|
func Benchmark_TimestampNano(b *testing.B) {
|
2019-04-06 22:48:47 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2020-01-20 14:14:11 +08:00
|
|
|
gtime.TimestampNano()
|
2019-04-06 22:48:47 +08:00
|
|
|
}
|
2018-06-21 11:44:58 +08:00
|
|
|
}
|
|
|
|
|
2018-11-23 09:20:45 +08:00
|
|
|
func Benchmark_StrToTime(b *testing.B) {
|
2019-04-06 22:48:47 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
gtime.StrToTime("2018-02-09T20:46:17.897Z")
|
|
|
|
}
|
2018-11-23 09:20:45 +08:00
|
|
|
}
|
|
|
|
|
2021-01-03 23:37:45 +08:00
|
|
|
func Benchmark_StrToTime_Format(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
gtime.StrToTime("2018-02-09 20:46:17.897", "Y-m-d H:i:su")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Benchmark_StrToTime_Layout(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
gtime.StrToTimeLayout("2018-02-09T20:46:17.897Z", time.RFC3339)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-23 09:20:45 +08:00
|
|
|
func Benchmark_ParseTimeFromContent(b *testing.B) {
|
2019-04-06 22:48:47 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
gtime.ParseTimeFromContent("2018-02-09T20:46:17.897Z")
|
|
|
|
}
|
2018-11-23 09:20:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func Benchmark_NewFromTimeStamp(b *testing.B) {
|
2019-04-06 22:48:47 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
gtime.NewFromTimeStamp(1542674930)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Benchmark_Date(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
gtime.Date()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Benchmark_Datetime(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
gtime.Datetime()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Benchmark_SetTimeZone(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
gtime.SetTimeZone("Asia/Shanghai")
|
|
|
|
}
|
|
|
|
}
|