Debian Codegraph @

hash64_test.go

raw
1 package xxh3
2
3 import (
4 "fmt"
5 "runtime"
6 "testing"
7 )
8
9 func BenchmarkFixed64(b *testing.B) {
10 r := func(i int) {
11 bench := func(b *testing.B) {
12 var acc uint64
13 d := string(make([]byte, i))
14 b.Run("default", func(b *testing.B) {
15 b.SetBytes(int64(i))
16 b.ResetTimer()
17 for i := 0; i < b.N; i++ {
18 acc = HashString(d)
19 }
20 runtime.KeepAlive(acc)
21 })
22 b.Run("seed", func(b *testing.B) {
23 b.SetBytes(int64(i))
24 b.ResetTimer()
25 for i := 0; i < b.N; i++ {
26 acc = HashStringSeed(d, 42)
27 }
28 runtime.KeepAlive(acc)
29 })
30
31 }
32
33 if i > 240 {
34 if i >= avx512Switch && hasAVX512 {
35 withAVX512(func() { b.Run(fmt.Sprintf("%d-AVX512", i), bench) })
36 }
37 if hasAVX2 {
38 withAVX2(func() { b.Run(fmt.Sprintf("%d-AVX2", i), bench) })
39 }
40 if hasSSE2 {
41 withSSE2(func() { b.Run(fmt.Sprintf("%d-SSE2", i), bench) })
42 }
43 }
44
45 withGeneric(func() { b.Run(fmt.Sprintf("%d", i), bench) })
46 }
47
48 r(0)
49 r(1)
50 r(2)
51 r(3)
52 r(4)
53 r(8)
54 r(9)
55 r(16)
56 r(17)
57 r(32)
58 r(33)
59 r(64)
60 r(65)
61 r(96)
62 r(97)
63 r(128)
64 r(129)
65 r(240)
66 r(241)
67 r(512)
68 r(1024)
69 r(8192)
70 r(100 * 1024)
71 r(1000 * 1024)
72 r(10000 * 1024)
73 r(100000 * 1024)
74 }