forked from twinj/uuid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmarks_test.go
176 lines (156 loc) · 2.93 KB
/
benchmarks_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package uuid_test
import (
. "github.com/twinj/uuid"
"testing"
)
var name UniqueName = Name("www.example.com")
func BenchmarkNewV1(b *testing.B) {
for i := 0; i < b.N; i++ {
NewV1() // Sets up initial store on first run
}
b.StopTimer()
b.ReportAllocs()
}
func BenchmarkNewV2(b *testing.B) {
for i := 0; i < b.N; i++ {
NewV2(DomainGroup)
}
b.StopTimer()
b.ReportAllocs()
}
func BenchmarkNewV3(b *testing.B) {
for i := 0; i < b.N; i++ {
NewV3(NameSpaceDNS, name)
}
b.StopTimer()
b.ReportAllocs()
}
func BenchmarkNewV4(b *testing.B) {
for i := 0; i < b.N; i++ {
NewV4()
}
b.StopTimer()
b.ReportAllocs()
}
func BenchmarkNewV5(b *testing.B) {
for i := 0; i < b.N; i++ {
NewV5(NameSpaceDNS, name)
}
b.StopTimer()
b.ReportAllocs()
}
func BenchmarkCompare(b *testing.B) {
for i := 0; i < b.N; i++ {
Compare(NameSpaceDNS, NameSpaceURL)
}
b.StopTimer()
b.ReportAllocs()
}
func BenchmarkEqual(b *testing.B) {
s := "f3593cff-ee92-40df-4086-87825b523f13"
id, _ := Parse(s)
b.ResetTimer()
for i := 0; i < b.N; i++ {
Equal(id, id)
}
b.StopTimer()
b.ReportAllocs()
}
func BenchmarkNew(b *testing.B) {
id := NewV2(DomainGroup).Bytes()
b.ResetTimer()
for i := 0; i < b.N; i++ {
New(id)
}
b.StopTimer()
b.ReportAllocs()
}
func BenchmarkNewHex(b *testing.B) {
s := "6ba7b8149dad11d180b400c04fd430c8"
b.ResetTimer()
for i := 0; i < b.N; i++ {
NewHex(s)
}
b.StopTimer()
b.ReportAllocs()
}
func BenchmarkParse(b *testing.B) {
s := "f3593cff-ee92-40df-4086-87825b523f13"
b.ResetTimer()
for i := 0; i < b.N; i++ {
Parse(s)
}
b.StopTimer()
b.ReportAllocs()
}
func BenchmarkNow(b *testing.B) {
for i := 0; i < b.N; i++ {
Now()
}
b.StopTimer()
b.ReportAllocs()
}
func BenchmarkFormatter(b *testing.B) {
id := NewV2(DomainGroup)
b.ResetTimer()
for i := 0; i < b.N; i++ {
Formatter(id, "{%X-%X-%X-%x-%X}")
}
b.StopTimer()
b.ReportAllocs()
}
func BenchmarkUuid_Bytes(b *testing.B) {
id := make(Uuid, 16)
copy(id, NameSpaceDNS.Bytes())
b.ResetTimer()
for i := 0; i < b.N; i++ {
id.Bytes()
}
b.StopTimer()
b.ReportAllocs()
}
func BenchmarkUuid_String_Canonical(b *testing.B) {
id := NewV2(DomainGroup)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = id.String()
}
b.StopTimer()
b.ReportAllocs()
}
func BenchmarkUuid_String_NonCanonical(b *testing.B) {
SwitchFormat(FormatUrn)
id := NewV2(DomainGroup)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = id.String()
}
b.StopTimer()
b.ReportAllocs()
SwitchFormat(FormatCanonical)
}
func BenchmarkUuid_Variant(b *testing.B) {
id := NewV2(DomainGroup)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = id.Variant()
}
b.StopTimer()
b.ReportAllocs()
}
func BenchmarkUuid_Version(b *testing.B) {
id := NewV2(DomainGroup)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = id.Version()
}
b.StopTimer()
b.ReportAllocs()
}
func BenchmarkNameSpace_Bytes(b *testing.B) {
for i := 0; i < b.N; i++ {
NameSpaceDNS.Bytes()
}
b.StopTimer()
b.ReportAllocs()
}