Pārlūkot izejas kodu

updating tests + benchmark. found strings to be marginally faster (12500 ns/op vs []byte at ~15000 ns/op)

master
William Dillon pirms 3 gadiem
vecāks
revīzija
c37b14540e
1 mainītis faili ar 13 papildinājumiem un 5 dzēšanām
  1. 13
    5
      mishmash_test.go

+ 13
- 5
mishmash_test.go Parādīt failu

@@ -7,7 +7,7 @@ import (

func TestMishmash(t *testing.T) {
want := "9d923077"
if got := fmt.Sprintf("%08x", Mishmash([]byte("google.com"))); want != got {
if got := fmt.Sprintf("%08x", Mishmash("google.com")); want != got {
t.Error("Parse() = got", got, "want", want)
} else {
fmt.Println("TestMishmash Passed")
@@ -16,8 +16,8 @@ func TestMishmash(t *testing.T) {

func TestSecondHash(t *testing.T) {
want := "3fbdb348"
hash := Mishmash([]byte("google.com"))
if got := fmt.Sprintf("%08x", Mishmash([]byte("google.com"), uint64(hash))); want != got {
hash := Mishmash("google.com")
if got := fmt.Sprintf("%08x", Mishmash("google.com", uint64(hash))); want != got {
t.Error("Parse() = got", got, "want", want)
} else {
fmt.Println("TestSecondHash Passed")
@@ -26,7 +26,7 @@ func TestSecondHash(t *testing.T) {

func TestSeedOne(t *testing.T) {
want := "cebf5691"
if got := fmt.Sprintf("%08x", Mishmash([]byte("google.com"), uint64(1))); want != got {
if got := fmt.Sprintf("%08x", Mishmash("google.com", uint64(1))); want != got {
t.Error("Parse() = got", got, "want", want)
} else {
fmt.Println("TestSeedOne Passed")
@@ -35,7 +35,7 @@ func TestSeedOne(t *testing.T) {

func TestEngineAndAccumulator(t *testing.T) {
want := "65df1304"
test := []byte("google.com")
test := "google.com"
accum := Engine(test, len(test), 0)
if got := fmt.Sprintf("%08x", Mishmash(test, accum)); want != got {
t.Error("Parse() = got", got, "want", want)
@@ -43,3 +43,11 @@ func TestEngineAndAccumulator(t *testing.T) {
fmt.Println("TestEngineAndAccumulator Passed")
}
}

func BenchmarkHashGeneration(b *testing.B) {
test := "google.com"
for i := 0; i < b.N; i++ {
accum := uint64(Mishmash(test, 0))<<32 | uint64(Mishmash(test, 1))
fmt.Printf("%016x\n", accum)
}
}

Notiek ielāde…
Atcelt
Saglabāt