Debian Codegraph @

internal/compare/compare_test.go

raw
1 package compare
2
3 import (
4 "fmt"
5 "testing"
6
7 "github.com/cespare/xxhash"
8 "github.com/zeebo/xxh3"
9 )
10
11 var acc uint64
12
13 func BenchmarkCompare(b *testing.B) {
14 sizes := []int{
15 0, 1, 3, 4, 8, 9, 16, 17, 32,
16 33, 64, 65, 96, 97, 128, 129, 240, 241,
17 512, 1024, 100 * 1024,
18 }
19
20 b.Run("Zeebo", func(b *testing.B) {
21 for _, size := range sizes {
22 b.Run(fmt.Sprintf("%d", size), func(b *testing.B) {
23 b.SetBytes(int64(size))
24 d := string(make([]byte, size))
25 b.ReportAllocs()
26 b.ResetTimer()
27
28 for i := 0; i < b.N; i++ {
29 acc += xxh3.HashString(d)
30 }
31 })
32 }
33 })
34
35 b.Run("Cespare", func(b *testing.B) {
36 for _, size := range sizes {
37 b.Run(fmt.Sprintf("%d", size), func(b *testing.B) {
38 b.SetBytes(int64(size))
39 d := string(make([]byte, size))
40 b.ReportAllocs()
41 b.ResetTimer()
42
43 for i := 0; i < b.N; i++ {
44 acc += xxhash.Sum64String(d)
45 }
46 })
47 }
48 })
49 }