Debian Codegraph @

bench_test.go

raw symbols SCIP
1 package farm
2
3 import (
4 "strconv"
5 "testing"
6 )
7
8 var res32 uint32
9 var res64 uint64
10 var res64lo, res64hi uint64
11
12 // 256-bytes random string
13 var buf = make([]byte, 8192)
14
15 var sizes = []int{8, 16, 32, 40, 60, 64, 72, 80, 100, 150, 200, 250, 512, 1024, 8192}
16
17 func BenchmarkHash32(b *testing.B) {
18 var r uint32
19
20 for _, n := range sizes {
21 b.Run(strconv.Itoa(n), func(b *testing.B) {
22 b.SetBytes(int64(n))
23 for i := 0; i < b.N; i++ {
24 // record the result to prevent the compiler eliminating the function call
25 r = Hash32(buf[:n])
26 }
27 // store the result to a package level variable so the compiler cannot eliminate the Benchmark itself
28 res32 = r
29 })
30 }
31
32 }
33
34 func BenchmarkFingerprint32(b *testing.B) {
35 var r uint32
36
37 for _, n := range sizes {
38 b.Run(strconv.Itoa(n), func(b *testing.B) {
39 b.SetBytes(int64(n))
40 for i := 0; i < b.N; i++ {
41 // record the result to prevent the compiler eliminating the function call
42 r = Fingerprint32(buf[:n])
43 }
44 // store the result to a package level variable so the compiler cannot eliminate the Benchmark itself
45 res32 = r
46 })
47 }
48
49 }
50
51 func BenchmarkHash64(b *testing.B) {
52 var r uint64
53
54 for _, n := range sizes {
55 b.Run(strconv.Itoa(n), func(b *testing.B) {
56 for i := 0; i < b.N; i++ {
57 r = Hash64(buf[:n])
58 }
59 res64 = r
60 })
61 }
62
63 }
64
65 func BenchmarkFingerprint64(b *testing.B) {
66 var r uint64
67
68 for _, n := range sizes {
69 b.Run(strconv.Itoa(n), func(b *testing.B) {
70 b.SetBytes(int64(n))
71 for i := 0; i < b.N; i++ {
72 r = Fingerprint64(buf[:n])
73 }
74 res64 = r
75 })
76 }
77 }
78
79 func BenchmarkHash128(b *testing.B) {
80 var rlo, rhi uint64
81
82 for _, n := range sizes {
83 b.Run(strconv.Itoa(n), func(b *testing.B) {
84
85 for i := 0; i < b.N; i++ {
86 rlo, rhi = Hash128(buf)
87 }
88 res64lo = rlo
89 res64hi = rhi
90
91 })
92 }
93 }