mirror of
https://github.com/golang/go
synced 2024-11-18 10:04:43 -07:00
Reduce crc32 benchmark memory usage
Reset the length of the slice where save the result to recycle the same allocated memory and prevent further allocations. The Sum function uses append, so the length of the "in" slice increased with each cycle of the benchmark.
This commit is contained in:
parent
7d1bf79faa
commit
b8777ee213
@ -329,11 +329,14 @@ func benchmark(b *testing.B, h hash.Hash32, n, alignment int64) {
|
|||||||
h.Reset()
|
h.Reset()
|
||||||
h.Write(data)
|
h.Write(data)
|
||||||
h.Sum(in)
|
h.Sum(in)
|
||||||
|
// Avoid further allocations
|
||||||
|
in = in[:0]
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
h.Reset()
|
h.Reset()
|
||||||
h.Write(data)
|
h.Write(data)
|
||||||
h.Sum(in)
|
h.Sum(in)
|
||||||
|
in = in[:0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user