chunker: move buffer pool to chunker package

This commit is contained in:
Alexander Neumann
2015-05-05 00:45:29 +02:00
parent bdbb3ab329
commit ea22b2dfb1
4 changed files with 26 additions and 42 deletions

View File

@@ -25,9 +25,9 @@ type Rdr interface {
io.ReaderAt
}
func benchmarkChunkEncrypt(b testing.TB, buf, buf2, chunkBuf []byte, rd Rdr, key *crypto.Key) {
func benchmarkChunkEncrypt(b testing.TB, buf, buf2 []byte, rd Rdr, key *crypto.Key) {
rd.Seek(0, 0)
ch := chunker.New(rd, testPol, chunkBuf, sha256.New())
ch := chunker.New(rd, testPol, sha256.New())
for {
chunk, err := ch.Next()
@@ -58,18 +58,17 @@ func BenchmarkChunkEncrypt(b *testing.B) {
buf := make([]byte, chunker.MaxSize)
buf2 := make([]byte, chunker.MaxSize)
chunkBuf := make([]byte, chunkerBufSize)
b.ResetTimer()
b.SetBytes(int64(len(data)))
for i := 0; i < b.N; i++ {
benchmarkChunkEncrypt(b, buf, buf2, chunkBuf, rd, s.Key())
benchmarkChunkEncrypt(b, buf, buf2, rd, s.Key())
}
}
func benchmarkChunkEncryptP(b *testing.PB, buf, chunkBuf []byte, rd Rdr, key *crypto.Key) {
ch := chunker.New(rd, testPol, chunkBuf, sha256.New())
func benchmarkChunkEncryptP(b *testing.PB, buf []byte, rd Rdr, key *crypto.Key) {
ch := chunker.New(rd, testPol, sha256.New())
for {
chunk, err := ch.Next()
@@ -91,7 +90,6 @@ func BenchmarkChunkEncryptParallel(b *testing.B) {
data := Random(23, 10<<20) // 10MiB
buf := make([]byte, chunker.MaxSize)
chunkBuf := make([]byte, chunkerBufSize)
b.ResetTimer()
b.SetBytes(int64(len(data)))
@@ -99,7 +97,7 @@ func BenchmarkChunkEncryptParallel(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
rd := bytes.NewReader(data)
benchmarkChunkEncryptP(pb, buf, chunkBuf, rd, s.Key())
benchmarkChunkEncryptP(pb, buf, rd, s.Key())
}
})
}