func testEquality(t *testing.T, v []byte) { ch64, ch32 := cxx.Checksum64(v), cxx.Checksum32(v) if h := N.Checksum64(v); ch64 != h { t.Fatalf("Checksum64 doesn't match, len = %d, expected 0x%X, got 0x%X", len(v), ch64, h) } if h := N.Checksum32(v); ch32 != h { t.Fatalf("Checksum32 doesn't match, len = %d, expected 0x%X, got 0x%X", len(v), ch32, h) } h64 := N.New64() h64.Write(v) if h := h64.Sum64(); ch64 != h { t.Fatalf("Sum64() doesn't match, len = %d, expected 0x%X, got 0x%X", len(v), ch64, h) } h32 := N.New32() h32.Write(v) if h := h32.Sum32(); ch32 != h { t.Fatalf("Sum32() doesn't match, len = %d, expected 0x%X, got 0x%X", len(v), ch32, h) } }
func TestReset64(t *testing.T) { h := N.New64() // p1 := "http" p2 := "://" p3 := "www.marmiton.org" p4 := "/recettes/recherche.aspx" p5 := "?st=2&aqt=gateau&" url := p1 + p2 + p3 + p4 + p5 // compute hash by parts h.Write([]byte(p1)) h.Write([]byte(p2)) h.Write([]byte(p3)) h.Write([]byte(p4)) h.Write([]byte(p5)) s1 := h.Sum64() h.Reset() h.Write([]byte(url)) s2 := h.Sum64() // should be the same, right ? if s1 != s2 { t.Errorf("s1 != s2 %x %x", s1, s2) } }
func BenchmarkXxhash64MultiWrites(b *testing.B) { h := N.New64() for i := 0; i < b.N; i++ { h.Write(in) } _ = h.Sum64() }
func TestHash64(t *testing.T) { h := N.New64() h.Write(in) r := h.Sum64() if r != expected64 { t.Errorf("expected 0x%x, got 0x%x.", expected64, r) } }
func BenchmarkXX64MultiWrites(b *testing.B) { var bv uint64 h := N.New64() for i := 0; i < b.N; i++ { h.Write(in) bv += h.Sum64() h.Reset() } }
func BenchmarkXxhash64MultiWrites(b *testing.B) { var bv uint64 h := N.New64() for i := 0; i < b.N; i++ { h.Write(in) bv = h.Sum64() h.Reset() } benchVal64 = bv }