internal/deephash: add re-usable scratch space
name old time/op new time/op delta Hash-8 13.9µs ± 0% 12.5µs ± 0% -10.10% (p=0.008 n=5+5) name old alloc/op new alloc/op delta Hash-8 793B ± 0% 793B ± 0% ~ (all equal) name old allocs/op new allocs/op delta Hash-8 14.0 ± 0% 12.0 ± 0% -14.29% (p=0.008 n=5+5) Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:

committed by
Josh Bleecher Snyder

parent
988dfcabef
commit
135b641332
@ -96,10 +96,11 @@ func TestHashMapAcyclic(t *testing.T) {
|
||||
|
||||
for i := 0; i < 20; i++ {
|
||||
visited := map[uintptr]bool{}
|
||||
scratch := make([]byte, 0, 64)
|
||||
v := reflect.ValueOf(m)
|
||||
buf.Reset()
|
||||
bw.Reset(&buf)
|
||||
if !hashMapAcyclic(bw, v, visited) {
|
||||
if !hashMapAcyclic(bw, v, visited, scratch) {
|
||||
t.Fatal("returned false")
|
||||
}
|
||||
if got[string(buf.Bytes())] {
|
||||
@ -122,12 +123,13 @@ func BenchmarkHashMapAcyclic(b *testing.B) {
|
||||
var buf bytes.Buffer
|
||||
bw := bufio.NewWriter(&buf)
|
||||
visited := map[uintptr]bool{}
|
||||
scratch := make([]byte, 0, 64)
|
||||
v := reflect.ValueOf(m)
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
buf.Reset()
|
||||
bw.Reset(&buf)
|
||||
if !hashMapAcyclic(bw, v, visited) {
|
||||
if !hashMapAcyclic(bw, v, visited, scratch) {
|
||||
b.Fatal("returned false")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user