Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions tests/runtime/memhash_test.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
package main

import (
"hash/maphash"
"strconv"
"testing"
"hash/maphash"
"strconv"
"testing"
)

var buf [8192]byte

func BenchmarkMaphash(b *testing.B) {
var h maphash.Hash
benchmarkHash(b, "maphash", h)
var h maphash.Hash
benchmarkHash(b, "maphash", &h)
}

func benchmarkHash(b *testing.B, str string, h maphash.Hash) {
var sizes = []int{1, 2, 3, 4, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1024, 8192}
for _, n := range sizes {
b.Run(strconv.Itoa(n), func(b *testing.B) { benchmarkHashn(b, int64(n), h) })
}
func benchmarkHash(b *testing.B, str string, h *maphash.Hash) {
var sizes = []int{1, 2, 3, 4, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1024, 8192}
for _, n := range sizes {
b.Run(strconv.Itoa(n), func(b *testing.B) { benchmarkHashn(b, int64(n), h) })
}
}

var total uint64

func benchmarkHashn(b *testing.B, size int64, h maphash.Hash) {
b.SetBytes(size)

sum := make([]byte, 4)

for i := 0; i < b.N; i++ {
h.Reset()
h.Write(buf[:size])
sum = h.Sum(sum[:0])
total += uint64(sum[0])
}
func benchmarkHashn(b *testing.B, size int64, h *maphash.Hash) {
b.SetBytes(size)
sum := make([]byte, 4)
for i := 0; i < b.N; i++ {
h.Reset()
h.Write(buf[:size])
h.Sum(sum[:0])
total += uint64(sum[0])
}
}