-
Notifications
You must be signed in to change notification settings - Fork 124
/
bench_test.go
75 lines (69 loc) · 1.23 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
package xxhash
import (
"strings"
"testing"
)
var benchmarks = []struct {
name string
n int64
}{
{"4B", 4},
{"16B", 16},
{"100B", 100},
{"4KB", 4e3},
{"10MB", 10e6},
}
func BenchmarkSum64(b *testing.B) {
for _, bb := range benchmarks {
in := make([]byte, bb.n)
for i := range in {
in[i] = byte(i)
}
b.Run(bb.name, func(b *testing.B) {
b.SetBytes(bb.n)
for i := 0; i < b.N; i++ {
_ = Sum64(in)
}
})
}
}
func BenchmarkSum64String(b *testing.B) {
for _, bb := range benchmarks {
s := strings.Repeat("a", int(bb.n))
b.Run(bb.name, func(b *testing.B) {
b.SetBytes(bb.n)
for i := 0; i < b.N; i++ {
_ = Sum64String(s)
}
})
}
}
func BenchmarkDigestBytes(b *testing.B) {
for _, bb := range benchmarks {
in := make([]byte, bb.n)
for i := range in {
in[i] = byte(i)
}
b.Run(bb.name, func(b *testing.B) {
b.SetBytes(bb.n)
for i := 0; i < b.N; i++ {
h := New()
h.Write(in)
_ = h.Sum64()
}
})
}
}
func BenchmarkDigestString(b *testing.B) {
for _, bb := range benchmarks {
s := strings.Repeat("a", int(bb.n))
b.Run(bb.name, func(b *testing.B) {
b.SetBytes(bb.n)
for i := 0; i < b.N; i++ {
h := New()
h.WriteString(s)
_ = h.Sum64()
}
})
}
}