mirror of
https://github.com/golang/go
synced 2024-11-24 21:00:09 -07:00
compress/flate: use bytes.NewReader instead of NewBuffer in test
Also, report allocations in benchmark. R=golang-dev, r CC=golang-dev https://golang.org/cl/13410044
This commit is contained in:
parent
80f39f7b73
commit
fca660892d
@ -37,6 +37,7 @@ var testfiles = []string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func benchmarkDecode(b *testing.B, testfile, level, n int) {
|
func benchmarkDecode(b *testing.B, testfile, level, n int) {
|
||||||
|
b.ReportAllocs()
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
b.SetBytes(int64(n))
|
b.SetBytes(int64(n))
|
||||||
buf0, err := ioutil.ReadFile(testfiles[testfile])
|
buf0, err := ioutil.ReadFile(testfiles[testfile])
|
||||||
@ -55,7 +56,7 @@ func benchmarkDecode(b *testing.B, testfile, level, n int) {
|
|||||||
if len(buf0) > n-i {
|
if len(buf0) > n-i {
|
||||||
buf0 = buf0[:n-i]
|
buf0 = buf0[:n-i]
|
||||||
}
|
}
|
||||||
io.Copy(w, bytes.NewBuffer(buf0))
|
io.Copy(w, bytes.NewReader(buf0))
|
||||||
}
|
}
|
||||||
w.Close()
|
w.Close()
|
||||||
buf1 := compressed.Bytes()
|
buf1 := compressed.Bytes()
|
||||||
@ -63,7 +64,7 @@ func benchmarkDecode(b *testing.B, testfile, level, n int) {
|
|||||||
runtime.GC()
|
runtime.GC()
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
io.Copy(ioutil.Discard, NewReader(bytes.NewBuffer(buf1)))
|
io.Copy(ioutil.Discard, NewReader(bytes.NewReader(buf1)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user