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

Commit cd78345

Browse files
committed
Add benchmarks
License: MIT Signed-off-by: Jakub Sztandera <[email protected]>
1 parent f9e6481 commit cd78345

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ require (
77
github.com/libp2p/go-buffer-pool v0.0.1
88
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f
99
)
10+
11+
go 1.12

rabin_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,32 @@ func TestRabinChunkReuse(t *testing.T) {
7979
t.Log("too many spare chunks made")
8080
}
8181
}
82+
83+
var Res uint64
84+
85+
func BenchmarkRabin(b *testing.B) {
86+
data := make([]byte, 16<<20)
87+
util.NewTimeSeededRand().Read(data)
88+
89+
b.SetBytes(16 << 20)
90+
b.ReportAllocs()
91+
b.ResetTimer()
92+
93+
var res uint64
94+
95+
for i := 0; i < b.N; i++ {
96+
r := NewRabin(bytes.NewReader(data), 1024*256)
97+
98+
for {
99+
chunk, err := r.NextBytes()
100+
if err != nil {
101+
if err == io.EOF {
102+
break
103+
}
104+
b.Fatal(err)
105+
}
106+
res = res + uint64(len(chunk))
107+
}
108+
}
109+
Res = Res + res
110+
}

splitting_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77

88
u "github.com/ipfs/go-ipfs-util"
9+
util "github.com/ipfs/go-ipfs-util"
910
)
1011

1112
func randBuf(t *testing.T, size int) []byte {
@@ -118,3 +119,30 @@ func (s *clipReader) Read(buf []byte) (int, error) {
118119

119120
return s.r.Read(buf)
120121
}
122+
123+
func BenchmarkDefault(b *testing.B) {
124+
data := make([]byte, 16<<20)
125+
util.NewTimeSeededRand().Read(data)
126+
127+
b.SetBytes(16 << 20)
128+
b.ReportAllocs()
129+
b.ResetTimer()
130+
131+
var res uint64
132+
133+
for i := 0; i < b.N; i++ {
134+
r := DefaultSplitter(bytes.NewReader(data))
135+
136+
for {
137+
chunk, err := r.NextBytes()
138+
if err != nil {
139+
if err == io.EOF {
140+
break
141+
}
142+
b.Fatal(err)
143+
}
144+
res = res + uint64(len(chunk))
145+
}
146+
}
147+
Res = Res + res
148+
}

0 commit comments

Comments
 (0)