...
1 package xxh3
2
3 import (
4 "fmt"
5 "runtime"
6 "testing"
7 )
8
9 func BenchmarkFixed128(b *testing.B) {
10 r := func(i int) {
11 bench := func(b *testing.B) {
12 var acc Uint128
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 = HashString128(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 = HashString128Seed(d, 42)
27 }
28 runtime.KeepAlive(acc)
29 })
30 }
31
32 if i > 240 {
33 if i >= avx512Switch && hasAVX512 {
34 withAVX512(func() { b.Run(fmt.Sprintf("%d-AVX512", i), bench) })
35 }
36 if hasAVX2 {
37 withAVX2(func() { b.Run(fmt.Sprintf("%d-AVX2", i), bench) })
38 }
39 if hasSSE2 {
40 withSSE2(func() { b.Run(fmt.Sprintf("%d-SSE2", i), bench) })
41 }
42 }
43
44 withGeneric(func() { b.Run(fmt.Sprintf("%d", i), bench) })
45 }
46 r(0)
47 r(1)
48 r(2)
49 r(3)
50 r(4)
51 r(8)
52 r(9)
53 r(16)
54 r(17)
55 r(32)
56 r(33)
57 r(64)
58 r(65)
59 r(96)
60 r(97)
61 r(128)
62 r(129)
63 r(240)
64 r(241)
65 r(512)
66 r(1024)
67 r(8192)
68 r(100 * 1024)
69 r(1000 * 1024)
70 r(10000 * 1024)
71 r(100000 * 1024)
72 }
73
View as plain text