-
Notifications
You must be signed in to change notification settings - Fork 0
/
uuid_test.go
58 lines (46 loc) · 893 Bytes
/
uuid_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
package main
import (
"runtime"
"testing"
"github.com/google/uuid"
)
var (
testUUIDStr = "b943846e-dc8f-4726-bf8f-f7169ca264e7"
testUUID = uuid.MustParse(testUUIDStr)
)
func genUUID() uuid.UUID {
return uuid.New()
}
func marshalUUID(id string) uuid.UUID {
return uuid.MustParse(id)
}
func unmarshalUUID(id uuid.UUID) string {
return id.String()
}
func BenchmarkGenUUID(b *testing.B) {
b.ResetTimer()
b.Run("genUUID", func(b *testing.B) {
for i := 0; i < c; i++ {
genUUID()
}
runtime.GC()
})
}
func BenchmarkMarshalUUID(b *testing.B) {
b.ResetTimer()
b.Run("marshalUUID", func(b *testing.B) {
for i := 0; i < c; i++ {
marshalUUID(testUUIDStr)
}
runtime.GC()
})
}
func BenchmarkUnmarshalUUID(b *testing.B) {
b.ResetTimer()
b.Run("unmarshalUUID", func(b *testing.B) {
for i := 0; i < c; i++ {
unmarshalUUID(testUUID)
}
runtime.GC()
})
}