before & after:
adler32.BenchmarkGolden 100000 14747 ns/op
adler32.BenchmarkGolden 200000 8761 ns/op
Found by profiling PNG encoding.
R=rsc, bradfitzwork, eds
CC=golang-dev
https://golang.org/cl/
4441073
// Add p to the running checksum a, b.
func update(a, b uint32, p []byte) (aa, bb uint32) {
- for i := 0; i < len(p); i++ {
- a += uint32(p[i])
+ for _, pi := range p {
+ a += uint32(pi)
b += a
// invariant: a <= b
if b > (0xffffffff-255)/2 {
package adler32
import (
+ "bytes"
"io"
"testing"
)
}
}
}
+
+func BenchmarkGolden(b *testing.B) {
+ b.StopTimer()
+ c := New()
+ var buf bytes.Buffer
+ for _, g := range golden {
+ buf.Write([]byte(g.in))
+ }
+ b.StartTimer()
+ for i := 0; i < b.N; i++ {
+ c.Write(buf.Bytes())
+ }
+}