forked from RobinUS2/golang-encrypted-uuid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bench_test.go
143 lines (122 loc) · 3.25 KB
/
bench_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
package enc_uuid_test
import (
"github.com/FlxOne/golang-encrypted-uuid"
"github.com/nu7hatch/gouuid"
"testing"
)
const KEY_AES_128 string = "mysecret90123456"
const KEY_AES_192 string = "mysecret9012345612345678"
const KEY_AES_256 string = "mysecret901234561234567812345678"
// Without encryption creation
func BenchmarkCreatePlain(b *testing.B) {
for n := 0; n < b.N; n++ {
u, _ := uuid.NewV4()
u.String()
}
}
// Without encryption reading
func BenchmarkReadPlain(b *testing.B) {
str := "123fa63d-2afd-4234-4e31-26af1f24d0f5"
for n := 0; n < b.N; n++ {
uuid, _ := uuid.ParseHex(str)
uuid.String()
}
}
// Without encryption reading
func BenchmarkCreateReadPlain(b *testing.B) {
for n := 0; n < b.N; n++ {
u, _ := uuid.NewV4()
str := u.String()
uuid, _ := uuid.ParseHex(str)
uuid.String()
}
}
func BenchmarkCreateAes128(b *testing.B) {
generator := enc_uuid.New([]byte(KEY_AES_128), true)
doWrite(b, generator)
}
func BenchmarkReadAes128(b *testing.B) {
generator := enc_uuid.New([]byte(KEY_AES_128), true)
doRead(b, generator)
}
func BenchmarkReadGraceAes128(b *testing.B) {
generator := enc_uuid.New([]byte(KEY_AES_128), true)
doReadGraceful(b, generator)
}
func BenchmarkCreateReadAes128(b *testing.B) {
generator := enc_uuid.New([]byte(KEY_AES_128), true)
doWriteThenRead(b, generator)
}
func BenchmarkCreateAes192(b *testing.B) {
generator := enc_uuid.New([]byte(KEY_AES_192), true)
doWrite(b, generator)
}
func BenchmarkReadAes192(b *testing.B) {
generator := enc_uuid.New([]byte(KEY_AES_192), true)
doRead(b, generator)
}
func BenchmarkReadGraceAes192(b *testing.B) {
generator := enc_uuid.New([]byte(KEY_AES_192), true)
doReadGraceful(b, generator)
}
func BenchmarkCreateReadAes192(b *testing.B) {
generator := enc_uuid.New([]byte(KEY_AES_192), true)
doWriteThenRead(b, generator)
}
func BenchmarkCreateAes256(b *testing.B) {
generator := enc_uuid.New([]byte(KEY_AES_256), true)
doWrite(b, generator)
}
func BenchmarkReadAes256(b *testing.B) {
generator := enc_uuid.New([]byte(KEY_AES_256), true)
doRead(b, generator)
}
func BenchmarkReadGraceAes256(b *testing.B) {
generator := enc_uuid.New([]byte(KEY_AES_256), true)
doReadGraceful(b, generator)
}
func BenchmarkCreateReadAes256(b *testing.B) {
generator := enc_uuid.New([]byte(KEY_AES_256), true)
doWriteThenRead(b, generator)
}
func doWriteThenRead(b *testing.B, generator *enc_uuid.EncUuidGenerator) {
for n := 0; n < b.N; n++ {
u := generator.New()
str := u.ToString()
parsed, e := generator.Parse(str)
if e != nil {
panic("Failed parse")
}
_, e2 := parsed.UuidStr(generator)
if e2 != nil {
panic("Failed to uuid")
}
}
}
func doWrite(b *testing.B, generator *enc_uuid.EncUuidGenerator) {
for n := 0; n < b.N; n++ {
u := generator.New()
u.ToString()
}
}
func doRead(b *testing.B, generator *enc_uuid.EncUuidGenerator) {
u := generator.New()
str := u.ToString()
for n := 0; n < b.N; n++ {
parsed, e := generator.Parse(str)
if e != nil {
panic("Failed parse")
}
parsed.UuidStr(generator)
}
}
func doReadGraceful(b *testing.B, generator *enc_uuid.EncUuidGenerator) {
str := "123fa63d-2afd-4234-4e31-26af1f24d0f5"
for n := 0; n < b.N; n++ {
parsed, e := generator.Parse(str)
if e != nil {
panic("Failed parse")
}
parsed.UuidStr(generator)
}
}