Exemplo n.º 1
0
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)
	}
}
Exemplo n.º 2
0
func BenchmarkXxhash64(b *testing.B) {
	var bv uint64
	for i := 0; i < b.N; i++ {
		bv = N.Checksum64(in)
	}
	benchVal64 = bv
}
Exemplo n.º 3
0
func BenchmarkXXChecksum64Short(b *testing.B) {
	var bv uint64
	k := []byte("Test-key-100")
	for i := 0; i < b.N; i++ {
		bv += N.Checksum64(k)
	}
}
Exemplo n.º 4
0
func BenchmarkXxhash64VeryShort(b *testing.B) {
	var bv uint64
	k := []byte("Test-key-100")
	for i := 0; i < b.N; i++ {
		bv = N.Checksum64(k)
	}
	benchVal64 = bv
}
Exemplo n.º 5
0
Arquivo: impl.go Projeto: na--/nedomi
// Get implements the balancing algorithm interface.
func (j *Jump) Get(path string) (*types.UpstreamAddress, error) {
	j.RLock()
	defer j.RUnlock()

	len := int64(len(j.buckets))
	if len == 0 {
		return nil, errors.New("No upstream addresses set!")
	}

	key := xxhash.Checksum64([]byte(path))

	var b int64 = -1
	var i int64

	for i < len {
		b = i
		key = key*2862933555777941757 + 1
		i = int64(float64(b+1) * (float64(int64(1)<<31) / float64((key>>33)+1)))
	}

	return j.buckets[i], nil
}
Exemplo n.º 6
0
func TestHash64Short(t *testing.T) {
	r := N.Checksum64(in)
	if r != expected64 {
		t.Errorf("expected 0x%x, got 0x%x.", expected64, r)
	}
}
Exemplo n.º 7
0
func BenchmarkCity16(b *testing.B) { benchmarkHashn(b, 16, hcity) }
func BenchmarkCity40(b *testing.B) { benchmarkHashn(b, 40, hcity) }
func BenchmarkCity64(b *testing.B) { benchmarkHashn(b, 64, hcity) }
func BenchmarkCity1K(b *testing.B) { benchmarkHashn(b, 1024, hcity) }
func BenchmarkCity8K(b *testing.B) { benchmarkHashn(b, 8192, hcity) }

var hmetro = func(k []byte) uint64 { return metro.Hash64(k, 0) }

func BenchmarkMetro8(b *testing.B)  { benchmarkHashn(b, 8, hmetro) }
func BenchmarkMetro16(b *testing.B) { benchmarkHashn(b, 16, hmetro) }
func BenchmarkMetro40(b *testing.B) { benchmarkHashn(b, 40, hmetro) }
func BenchmarkMetro64(b *testing.B) { benchmarkHashn(b, 64, hmetro) }
func BenchmarkMetro1K(b *testing.B) { benchmarkHashn(b, 1024, hmetro) }
func BenchmarkMetro8K(b *testing.B) { benchmarkHashn(b, 8192, hmetro) }

var hxxhash = func(k []byte) uint64 { return xxhash.Checksum64(k) }

func BenchmarkXXHash8(b *testing.B)  { benchmarkHashn(b, 8, hxxhash) }
func BenchmarkXXHash16(b *testing.B) { benchmarkHashn(b, 16, hxxhash) }
func BenchmarkXXHash40(b *testing.B) { benchmarkHashn(b, 40, hxxhash) }
func BenchmarkXXHash64(b *testing.B) { benchmarkHashn(b, 64, hxxhash) }
func BenchmarkXXHash1K(b *testing.B) { benchmarkHashn(b, 1024, hxxhash) }
func BenchmarkXXHash8K(b *testing.B) { benchmarkHashn(b, 8192, hxxhash) }

var fsthash = func(k []byte) uint64 { return fasthash.Hash64(0, k) }

func BenchmarkFasthash8(b *testing.B)  { benchmarkHashn(b, 8, fsthash) }
func BenchmarkFasthash16(b *testing.B) { benchmarkHashn(b, 16, fsthash) }
func BenchmarkFasthash40(b *testing.B) { benchmarkHashn(b, 40, fsthash) }
func BenchmarkFasthash64(b *testing.B) { benchmarkHashn(b, 64, fsthash) }
func BenchmarkFasthash1K(b *testing.B) { benchmarkHashn(b, 1024, fsthash) }
Exemplo n.º 8
0
func BenchmarkFasthash64(b *testing.B)  { benchmarkHash64(b, hfasthash) }
func BenchmarkFasthash128(b *testing.B) { benchmarkHash128(b, hfasthash) }
func BenchmarkFasthash1K(b *testing.B)  { benchmarkHash1K(b, hfasthash) }
func BenchmarkFasthash8K(b *testing.B)  { benchmarkHash8K(b, hfasthash) }

var hspooky = func(p []byte) uint64 { return spooky.Hash64(p) }

func BenchmarkSpooky8(b *testing.B)   { benchmarkHash8(b, hspooky) }
func BenchmarkSpooky16(b *testing.B)  { benchmarkHash16(b, hspooky) }
func BenchmarkSpooky40(b *testing.B)  { benchmarkHash40(b, hspooky) }
func BenchmarkSpooky64(b *testing.B)  { benchmarkHash64(b, hspooky) }
func BenchmarkSpooky128(b *testing.B) { benchmarkHash128(b, hspooky) }
func BenchmarkSpooky1K(b *testing.B)  { benchmarkHash1K(b, hspooky) }
func BenchmarkSpooky8K(b *testing.B)  { benchmarkHash8K(b, hspooky) }

var hxxhash = func(p []byte) uint64 { return xxhash.Checksum64(p) }

func BenchmarkXXHash8(b *testing.B)   { benchmarkHash8(b, hxxhash) }
func BenchmarkXXHash16(b *testing.B)  { benchmarkHash16(b, hxxhash) }
func BenchmarkXXHash40(b *testing.B)  { benchmarkHash40(b, hxxhash) }
func BenchmarkXXHash64(b *testing.B)  { benchmarkHash64(b, hxxhash) }
func BenchmarkXXHash128(b *testing.B) { benchmarkHash128(b, hxxhash) }
func BenchmarkXXHash1K(b *testing.B)  { benchmarkHash1K(b, hxxhash) }
func BenchmarkXXHash8K(b *testing.B)  { benchmarkHash8K(b, hxxhash) }

var hcity = func(p []byte) uint64 { return cityhash.CityHash64(p, uint32(len(p))) }

func BenchmarkCity8(b *testing.B)   { benchmarkHash8(b, hcity) }
func BenchmarkCity16(b *testing.B)  { benchmarkHash16(b, hcity) }
func BenchmarkCity40(b *testing.B)  { benchmarkHash40(b, hcity) }
func BenchmarkCity64(b *testing.B)  { benchmarkHash64(b, hcity) }
Exemplo n.º 9
0
func BenchmarkXxhash64VeryShort(b *testing.B) {
	k := []byte("Test-key-100")
	for i := 0; i < b.N; i++ {
		N.Checksum64(k)
	}
}
Exemplo n.º 10
0
func BenchmarkXxhash64(b *testing.B) {
	for i := 0; i < b.N; i++ {
		N.Checksum64(in)
	}
}
Exemplo n.º 11
0
func BenchmarkXXChecksum64(b *testing.B) {
	var bv uint64
	for i := 0; i < b.N; i++ {
		bv += N.Checksum64(in)
	}
}