Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Add benchmarks #15

Merged
merged 2 commits into from
Oct 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 29 additions & 0 deletions rabin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
30 changes: 30 additions & 0 deletions splitting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"testing"

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 {
Expand Down Expand Up @@ -118,3 +120,31 @@ 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))
pool.Put(chunk)
}
}
Res = Res + res
}