Add benchmarks

License: MIT
Signed-off-by: default avatarJakub Sztandera <kubuxu@protocol.ai>
parent f9e64815
......@@ -7,3 +7,5 @@ require (
github.com/libp2p/go-buffer-pool v0.0.1
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f
)
go 1.12
......@@ -79,3 +79,32 @@ func TestRabinChunkReuse(t *testing.T) {
t.Log("too many spare chunks made")
}
}
var Res uint64
func BenchmarkRabin(b *testing.B) {
data := make([]byte, 16<<20)
util.NewTimeSeededRand().Read(data)
b.SetBytes(16 << 20)
b.ReportAllocs()
b.ResetTimer()
var res uint64
for i := 0; i < b.N; i++ {
r := NewRabin(bytes.NewReader(data), 1024*256)
for {
chunk, err := r.NextBytes()
if err != nil {
if err == io.EOF {
break
}
b.Fatal(err)
}
res = res + uint64(len(chunk))
}
}
Res = Res + res
}
......@@ -6,6 +6,7 @@ import (
"testing"
u "github.com/ipfs/go-ipfs-util"
util "github.com/ipfs/go-ipfs-util"
)
func randBuf(t *testing.T, size int) []byte {
......@@ -118,3 +119,30 @@ func (s *clipReader) Read(buf []byte) (int, error) {
return s.r.Read(buf)
}
func BenchmarkDefault(b *testing.B) {
data := make([]byte, 16<<20)
util.NewTimeSeededRand().Read(data)
b.SetBytes(16 << 20)
b.ReportAllocs()
b.ResetTimer()
var res uint64
for i := 0; i < b.N; i++ {
r := DefaultSplitter(bytes.NewReader(data))
for {
chunk, err := r.NextBytes()
if err != nil {
if err == io.EOF {
break
}
b.Fatal(err)
}
res = res + uint64(len(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