@@ -39,13 +39,7 @@ func TestRabinChunking(t *testing.T) {
3939 }
4040}
4141
42- type cher interface {
43- NextBytes () ([]byte , error )
44- }
45-
46- type newChunker func (io.Reader ) cher
47-
48- func chunkData (t * testing.T , newC newChunker , data []byte ) map [string ]blocks.Block {
42+ func chunkData (t * testing.T , newC newSplitter , data []byte ) map [string ]blocks.Block {
4943 r := newC (bytes .NewReader (data ))
5044
5145 blkmap := make (map [string ]blocks.Block )
@@ -66,7 +60,7 @@ func chunkData(t *testing.T, newC newChunker, data []byte) map[string]blocks.Blo
6660 return blkmap
6761}
6862
69- func testReuse (t * testing.T , cr newChunker ) {
63+ func testReuse (t * testing.T , cr newSplitter ) {
7064 data := make ([]byte , 1024 * 1024 * 16 )
7165 util .NewTimeSeededRand ().Read (data )
7266
@@ -87,7 +81,7 @@ func testReuse(t *testing.T, cr newChunker) {
8781}
8882
8983func TestRabinChunkReuse (t * testing.T ) {
90- newRabin := func (r io.Reader ) cher {
84+ newRabin := func (r io.Reader ) Splitter {
9185 return NewRabin (r , 256 * 1024 )
9286 }
9387 testReuse (t , newRabin )
@@ -96,29 +90,7 @@ func TestRabinChunkReuse(t *testing.T) {
9690var Res uint64
9791
9892func BenchmarkRabin (b * testing.B ) {
99- const size = 1 << 10
100- data := make ([]byte , size )
101- util .NewTimeSeededRand ().Read (data )
102-
103- b .SetBytes (size )
104- b .ReportAllocs ()
105- b .ResetTimer ()
106-
107- var res uint64
108-
109- for i := 0 ; i < b .N ; i ++ {
110- r := NewRabin (bytes .NewReader (data ), 1024 * 256 )
111-
112- for {
113- chunk , err := r .NextBytes ()
114- if err != nil {
115- if err == io .EOF {
116- break
117- }
118- b .Fatal (err )
119- }
120- res = res + uint64 (len (chunk ))
121- }
122- }
123- Res = Res + res
93+ benchmarkChunker (b , func (r io.Reader ) Splitter {
94+ return NewRabin (r , 256 << 10 )
95+ })
12496}
0 commit comments