Debian Codegraph @

benchmarks_test.go

raw
1 package uuid_test
2
3 import (
4 . "github.com/twinj/uuid"
5 "testing"
6 )
7
8 var name UniqueName = Name("www.example.com")
9
10 func BenchmarkNewV1(b *testing.B) {
11 for i := 0; i < b.N; i++ {
12 NewV1() // Sets up initial store on first run
13 }
14 b.StopTimer()
15 b.ReportAllocs()
16 }
17
18 func BenchmarkNewV2(b *testing.B) {
19 for i := 0; i < b.N; i++ {
20 NewV2(DomainGroup)
21 }
22 b.StopTimer()
23 b.ReportAllocs()
24 }
25
26 func BenchmarkNewV3(b *testing.B) {
27 for i := 0; i < b.N; i++ {
28 NewV3(NameSpaceDNS, name)
29 }
30 b.StopTimer()
31 b.ReportAllocs()
32 }
33
34 func BenchmarkNewV4(b *testing.B) {
35 for i := 0; i < b.N; i++ {
36 NewV4()
37 }
38 b.StopTimer()
39 b.ReportAllocs()
40 }
41
42 func BenchmarkNewV5(b *testing.B) {
43 for i := 0; i < b.N; i++ {
44 NewV5(NameSpaceDNS, name)
45 }
46 b.StopTimer()
47 b.ReportAllocs()
48 }
49
50 func BenchmarkCompare(b *testing.B) {
51 for i := 0; i < b.N; i++ {
52 Compare(NameSpaceDNS, NameSpaceURL)
53 }
54 b.StopTimer()
55 b.ReportAllocs()
56 }
57
58 func BenchmarkEqual(b *testing.B) {
59 s := "f3593cff-ee92-40df-4086-87825b523f13"
60 id, _ := Parse(s)
61 b.ResetTimer()
62 for i := 0; i < b.N; i++ {
63 Equal(id, id)
64 }
65 b.StopTimer()
66 b.ReportAllocs()
67 }
68
69 func BenchmarkNew(b *testing.B) {
70 id := NewV2(DomainGroup).Bytes()
71 b.ResetTimer()
72 for i := 0; i < b.N; i++ {
73 New(id)
74 }
75 b.StopTimer()
76 b.ReportAllocs()
77 }
78
79 func BenchmarkNewHex(b *testing.B) {
80 s := "6ba7b8149dad11d180b400c04fd430c8"
81 b.ResetTimer()
82 for i := 0; i < b.N; i++ {
83 NewHex(s)
84 }
85 b.StopTimer()
86 b.ReportAllocs()
87 }
88
89 func BenchmarkParse(b *testing.B) {
90 s := "f3593cff-ee92-40df-4086-87825b523f13"
91 b.ResetTimer()
92 for i := 0; i < b.N; i++ {
93 Parse(s)
94 }
95 b.StopTimer()
96 b.ReportAllocs()
97 }
98
99 func BenchmarkNow(b *testing.B) {
100 for i := 0; i < b.N; i++ {
101 Now()
102 }
103 b.StopTimer()
104 b.ReportAllocs()
105 }
106
107 func BenchmarkFormatter(b *testing.B) {
108 id := NewV2(DomainGroup)
109 b.ResetTimer()
110 for i := 0; i < b.N; i++ {
111 Formatter(id, "{%X-%X-%X-%x-%X}")
112 }
113 b.StopTimer()
114 b.ReportAllocs()
115 }
116
117 func BenchmarkUuid_Bytes(b *testing.B) {
118 id := make(Uuid, 16)
119 copy(id, NameSpaceDNS.Bytes())
120 b.ResetTimer()
121 for i := 0; i < b.N; i++ {
122 id.Bytes()
123 }
124 b.StopTimer()
125 b.ReportAllocs()
126 }
127
128 func BenchmarkUuid_String_Canonical(b *testing.B) {
129 id := NewV2(DomainGroup)
130 b.ResetTimer()
131 for i := 0; i < b.N; i++ {
132 _ = id.String()
133 }
134 b.StopTimer()
135 b.ReportAllocs()
136 }
137
138 func BenchmarkUuid_String_NonCanonical(b *testing.B) {
139 SwitchFormat(FormatUrn)
140 id := NewV2(DomainGroup)
141 b.ResetTimer()
142 for i := 0; i < b.N; i++ {
143 _ = id.String()
144 }
145 b.StopTimer()
146 b.ReportAllocs()
147 SwitchFormat(FormatCanonical)
148 }
149
150 func BenchmarkUuid_Variant(b *testing.B) {
151 id := NewV2(DomainGroup)
152 b.ResetTimer()
153 for i := 0; i < b.N; i++ {
154 _ = id.Variant()
155 }
156 b.StopTimer()
157 b.ReportAllocs()
158 }
159
160 func BenchmarkUuid_Version(b *testing.B) {
161 id := NewV2(DomainGroup)
162 b.ResetTimer()
163 for i := 0; i < b.N; i++ {
164 _ = id.Version()
165 }
166 b.StopTimer()
167 b.ReportAllocs()
168 }
169
170 func BenchmarkNameSpace_Bytes(b *testing.B) {
171 for i := 0; i < b.N; i++ {
172 NameSpaceDNS.Bytes()
173 }
174 b.StopTimer()
175 b.ReportAllocs()
176 }