forked from dromara/carbon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbenchmark_test.go
42 lines (36 loc) · 910 Bytes
/
benchmark_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package carbon
import (
"testing"
"time"
)
func BenchmarkCarbon_SetLocation(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, loc := range locationList {
Now().SetLocation(loc)
}
}
}
func BenchmarkCarbon_SetTimezone(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, timezone := range timezoneList {
Now().SetTimezone(timezone)
}
}
}
var timezoneList = getTimezoneList()
var locationList = getLocationList()
func getTimezoneList() []string {
return []string{
Local, UTC, GMT, CST, EET, WET, CET, EST, MST, Cuba, Egypt, Eire, Greenwich, Iceland,
Iran, Israel, Jamaica, Japan, Libya, Poland, Portugal, PRC, Singapore, Turkey,
}
}
func getLocationList() []*time.Location {
timezoneList := getTimezoneList()
result := make([]*time.Location, 0, len(timezoneList))
for _, v := range timezoneList {
loc, _ := time.LoadLocation(v)
result = append(result, loc)
}
return result
}