File: bench_test.go

package info (click to toggle)
golang-github-dgryski-go-farm 0.0~git20171119.ac7624ea8da3-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 132 kB
  • sloc: makefile: 126
file content (37 lines) | stat: -rw-r--r-- 956 bytes parent folder | download | duplicates (2)
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
package farm

import "testing"

var res32 uint32
var res64 uint64
var res64lo, res64hi uint64

// 256-bytes random string
var buf = []byte("RMVx)@MLxH9M.WeGW-ktWwR3Cy1XS.,K~i@n-Y+!!yx4?AB%cM~l/#0=2:BOn7HPipG&o/6Qe<hU;$w1-~bU4Q7N&yk/8*Zz.Yg?zl9bVH/pXs6Bq^VdW#Z)NH!GcnH-UesRd@gDij?luVQ3;YHaQ<~SBm17G9;RWvGlsV7tpe*RCe=,?$nE1u9zvjd+rBMu7_Rg4)2AeWs^aaBr&FkC#rcwQ.L->I+Da7Qt~!C^cB2wq(^FGyB?kGQpd(G8I.A7")

func BenchmarkHash32(b *testing.B) {
	var r uint32
	for i := 0; i < b.N; i++ {
		// record the result to prevent the compiler eliminating the function call
		r = Hash32(buf)
	}
	// store the result to a package level variable so the compiler cannot eliminate the Benchmark itself
	res32 = r
}

func BenchmarkHash64(b *testing.B) {
	var r uint64
	for i := 0; i < b.N; i++ {
		r = Hash64(buf)
	}
	res64 = r
}

func BenchmarkHash128(b *testing.B) {
	var rlo, rhi uint64
	for i := 0; i < b.N; i++ {
		rlo, rhi = Hash128(buf)
	}
	res64lo = rlo
	res64hi = rhi
}