-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathnon_cryptogrphic_hash_function_test.go
216 lines (187 loc) · 3.8 KB
/
non_cryptogrphic_hash_function_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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
package main
import (
"crypto/md5"
"hash/adler32"
"hash/crc32"
"hash/crc64"
"hash/fnv"
"math/rand"
"testing"
"github.com/OneOfOne/xxhash"
"github.com/dchest/siphash"
"github.com/dgryski/go-farm"
"github.com/dgryski/go-highway"
metro "github.com/dgryski/go-metro"
"github.com/dgryski/go-spooky"
"github.com/spaolacci/murmur3"
"github.com/zhenjl/cityhash"
)
const testString = "kahfkgjfq2348r742gydi71382rvkjyaci71138yakdkchvk73773"
var testBytes = []byte(testString)
func BenchmarkHash32Fnv(b *testing.B) {
h := fnv.New32()
b.ResetTimer()
for i := 0; i < b.N; i++ {
h.Write(testBytes)
h.Sum32()
}
}
func BenchmarkHash32Fnva(b *testing.B) {
h := fnv.New32a()
b.ResetTimer()
for i := 0; i < b.N; i++ {
h.Write(testBytes)
h.Sum32()
}
}
func BenchmarkHash64Fnv(b *testing.B) {
h := fnv.New64()
b.ResetTimer()
for i := 0; i < b.N; i++ {
h.Write(testBytes)
h.Sum64()
}
}
func BenchmarkHash64Fnva(b *testing.B) {
h := fnv.New64a()
b.ResetTimer()
for i := 0; i < b.N; i++ {
h.Write(testBytes)
h.Sum64()
}
}
func BenchmarkHash32Crc(b *testing.B) {
h := crc32.NewIEEE()
b.ResetTimer()
for i := 0; i < b.N; i++ {
h.Write(testBytes)
h.Sum32()
}
}
func BenchmarkHash64Crc(b *testing.B) {
h := crc64.New(crc64.MakeTable(crc64.ISO))
b.ResetTimer()
for i := 0; i < b.N; i++ {
h.Write(testBytes)
h.Sum64()
}
}
func BenchmarkHash32Adler(b *testing.B) {
h := adler32.New()
b.ResetTimer()
for i := 0; i < b.N; i++ {
h.Write(testBytes)
h.Sum32()
}
}
func BenchmarkHash32Xxhash(b *testing.B) {
h := xxhash.New32()
b.ResetTimer()
for i := 0; i < b.N; i++ {
h.Write(testBytes)
h.Sum32()
}
}
func BenchmarkHash64Xxhash(b *testing.B) {
h := xxhash.New64()
b.ResetTimer()
for i := 0; i < b.N; i++ {
h.Write(testBytes)
h.Sum64()
}
}
func BenchmarkHash32Murmur3(b *testing.B) {
h := murmur3.New32()
b.ResetTimer()
for i := 0; i < b.N; i++ {
h.Write(testBytes)
h.Sum32()
}
}
func BenchmarkHash128Murmur3(b *testing.B) {
h := murmur3.New128()
b.ResetTimer()
for i := 0; i < b.N; i++ {
h.Write(testBytes)
h.Sum128()
}
}
func BenchmarkHash64CityHash(b *testing.B) {
for i := 0; i < b.N; i++ {
cityhash.CityHash64(testBytes, uint32(len(testBytes)))
}
}
func BenchmarkHash128CityHash(b *testing.B) {
for i := 0; i < b.N; i++ {
cityhash.CityHash128(testBytes, uint32(len(testBytes)))
}
}
func BenchmarkHash32FarmHash(b *testing.B) {
for i := 0; i < b.N; i++ {
farm.Hash32(testBytes)
}
}
func BenchmarkHash64FarmHash(b *testing.B) {
for i := 0; i < b.N; i++ {
farm.Hash64(testBytes)
}
}
func BenchmarkHash128FarmHash(b *testing.B) {
for i := 0; i < b.N; i++ {
farm.Hash128(testBytes)
}
}
func BenchmarkHash64SipHash(b *testing.B) {
k0 := rand.Uint64()
k1 := rand.Uint64()
for i := 0; i < b.N; i++ {
siphash.Hash(k0, k1, testBytes)
}
}
func BenchmarkHash128SipHash(b *testing.B) {
k0 := rand.Uint64()
k1 := rand.Uint64()
for i := 0; i < b.N; i++ {
siphash.Hash128(k0, k1, testBytes)
}
}
func BenchmarkHash64HighwayHash(b *testing.B) {
keys := highway.Lanes{}
for i := 0; i < b.N; i++ {
highway.Hash(keys, testBytes)
}
}
func BenchmarkHash32SpookyHash(b *testing.B) {
for i := 0; i < b.N; i++ {
spooky.Hash32(testBytes)
}
}
func BenchmarkHash64SpookyHash(b *testing.B) {
for i := 0; i < b.N; i++ {
spooky.Hash64(testBytes)
}
}
func BenchmarkHash128SpookyHash(b *testing.B) {
k0 := rand.Uint64()
k1 := rand.Uint64()
for i := 0; i < b.N; i++ {
spooky.Hash128(testBytes, &k0, &k1)
}
}
func BenchmarkHashMD5(b *testing.B) {
for i := 0; i < b.N; i++ {
md5.Sum(testBytes)
}
}
func BenchmarkHash64MetroHash(b *testing.B) {
seed := rand.Uint64()
for i := 0; i < b.N; i++ {
metro.Hash64(testBytes, seed)
}
}
func BenchmarkHash128MetroHash(b *testing.B) {
seed := rand.Uint64()
for i := 0; i < b.N; i++ {
metro.Hash128(testBytes, seed)
}
}