Unverified Commit 9a794d09 authored by Jakub Sztandera's avatar Jakub Sztandera Committed by GitHub

Merge pull request #15 from ipfs/feat/benchmarks

Add benchmarks
parents f9e64815 52ca04ea
...@@ -7,3 +7,5 @@ require ( ...@@ -7,3 +7,5 @@ require (
github.com/libp2p/go-buffer-pool v0.0.1 github.com/libp2p/go-buffer-pool v0.0.1
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f
) )
go 1.12
...@@ -79,3 +79,32 @@ func TestRabinChunkReuse(t *testing.T) { ...@@ -79,3 +79,32 @@ func TestRabinChunkReuse(t *testing.T) {
t.Log("too many spare chunks made") 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,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
"testing" "testing"
u "github.com/ipfs/go-ipfs-util" 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 { func randBuf(t *testing.T, size int) []byte {
...@@ -118,3 +120,31 @@ func (s *clipReader) Read(buf []byte) (int, error) { ...@@ -118,3 +120,31 @@ func (s *clipReader) Read(buf []byte) (int, error) {
return s.r.Read(buf) 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))
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