github.com/parquet-go/parquet-go@v0.20.0/bloom/xxhash/xxhash_test.go (about) 1 package xxhash_test 2 3 import ( 4 "testing" 5 6 "github.com/parquet-go/parquet-go/bloom/xxhash" 7 ) 8 9 func TestSum64(t *testing.T) { 10 for _, tt := range []struct { 11 name string 12 input string 13 want uint64 14 }{ 15 {"empty", "", 0xef46db3751d8e999}, 16 {"a", "a", 0xd24ec4f1a98c6e5b}, 17 {"as", "as", 0x1c330fb2d66be179}, 18 {"asd", "asd", 0x631c37ce72a97393}, 19 {"asdf", "asdf", 0x415872f599cea71e}, 20 { 21 "len=63", 22 // Exactly 63 characters, which exercises all code paths. 23 "Call me Ishmael. Some years ago--never mind how long precisely-", 24 0x02a2e85470d6fd96, 25 }, 26 } { 27 t.Run(tt.name, func(t *testing.T) { 28 if got := xxhash.Sum64([]byte(tt.input)); got != tt.want { 29 t.Fatalf("Sum64: got 0x%x; want 0x%x", got, tt.want) 30 } 31 }) 32 } 33 } 34 35 var benchmarks = []struct { 36 name string 37 n int64 38 }{ 39 {"4B", 4}, 40 {"16B", 16}, 41 {"100B", 100}, 42 {"4KB", 4e3}, 43 {"10MB", 10e6}, 44 } 45 46 func BenchmarkSum64(b *testing.B) { 47 for _, bb := range benchmarks { 48 in := make([]byte, bb.n) 49 for i := range in { 50 in[i] = byte(i) 51 } 52 b.Run(bb.name, func(b *testing.B) { 53 b.SetBytes(bb.n) 54 for i := 0; i < b.N; i++ { 55 _ = xxhash.Sum64(in) 56 } 57 }) 58 } 59 }