Don't use pools for result buffers

Don't return them either in benchmarks

License: MIT
Signed-off-by: default avatarJakub Sztandera <kubuxu@protocol.ai>
parent 9e34967a
......@@ -38,7 +38,12 @@ func (b *Buzhash) NextBytes() ([]byte, error) {
if err != nil {
if err == io.ErrUnexpectedEOF {
b.err = io.EOF
return buf[:n+b.n], nil
res := make([]byte, n+b.n)
copy(res, buf)
pool.Put(b.buf)
b.buf = nil
return res, nil
} else {
b.err = err
pool.Put(buf)
......@@ -60,8 +65,9 @@ func (b *Buzhash) NextBytes() ([]byte, error) {
state = bits.RotateLeft32(state, 1) ^ bytehash[buf[i-32]] ^ bytehash[buf[i]]
}
res := buf[:i]
b.buf = pool.Get(buzMax)
res := make([]byte, i)
copy(res, b.buf)
b.n = copy(b.buf, buf[i:])
return res, nil
......
......@@ -7,7 +7,6 @@ import (
"testing"
util "github.com/ipfs/go-ipfs-util"
pool "github.com/libp2p/go-buffer-pool"
)
func TestBuzhashChunking(t *testing.T) {
......@@ -49,10 +48,10 @@ func TestBuzhashChunkReuse(t *testing.T) {
}
func BenchmarkBuzhash(b *testing.B) {
data := make([]byte, 16<<20)
data := make([]byte, 1<<10)
util.NewTimeSeededRand().Read(data)
b.SetBytes(16 << 20)
b.SetBytes(int64(len(data)))
b.ReportAllocs()
b.ResetTimer()
......@@ -70,7 +69,6 @@ func BenchmarkBuzhash(b *testing.B) {
b.Fatal(err)
}
res = res + uint64(len(chunk))
pool.Put(chunk)
}
}
Res = Res + res
......
......@@ -96,10 +96,11 @@ func TestRabinChunkReuse(t *testing.T) {
var Res uint64
func BenchmarkRabin(b *testing.B) {
data := make([]byte, 16<<20)
const size = 1 << 10
data := make([]byte, size)
util.NewTimeSeededRand().Read(data)
b.SetBytes(16 << 20)
b.SetBytes(size)
b.ReportAllocs()
b.ResetTimer()
......
......@@ -7,7 +7,6 @@ import (
u "github.com/ipfs/go-ipfs-util"
util "github.com/ipfs/go-ipfs-util"
pool "github.com/libp2p/go-buffer-pool"
)
func randBuf(t *testing.T, size int) []byte {
......@@ -122,10 +121,11 @@ func (s *clipReader) Read(buf []byte) (int, error) {
}
func BenchmarkDefault(b *testing.B) {
data := make([]byte, 16<<20)
const size = 1 << 10
data := make([]byte, size)
util.NewTimeSeededRand().Read(data)
b.SetBytes(16 << 20)
b.SetBytes(size)
b.ReportAllocs()
b.ResetTimer()
......@@ -143,7 +143,6 @@ func BenchmarkDefault(b *testing.B) {
b.Fatal(err)
}
res = res + uint64(len(chunk))
pool.Put(chunk)
}
}
Res = Res + res
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment