2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 19:08:55 +00:00

Fix benchmarks for ChunkEncrypt

This commit is contained in:
Alexander Neumann 2015-02-17 20:02:43 +01:00
parent af57fb86d7
commit 43ae0b69ab

View File

@ -30,12 +30,12 @@ func randomReader(seed, size int) *bytes.Reader {
const bufSize = chunker.MiB
func benchmarkChunkEncrypt(b testing.TB, rd interface {
type Rdr interface {
io.ReadSeeker
io.ReaderAt
}, key *restic.Key) {
chunkBuf := make([]byte, restic.CiphertextExtension+chunker.MaxSize)
}
func benchmarkChunkEncrypt(b testing.TB, buf []byte, rd Rdr, key *restic.Key) {
ch := restic.GetChunker("BenchmarkChunkEncrypt")
rd.Seek(0, 0)
ch.Reset(rd)
@ -49,13 +49,13 @@ func benchmarkChunkEncrypt(b testing.TB, rd interface {
ok(b, err)
// reduce length of chunkBuf
chunkBuf = chunkBuf[:chunk.Length]
n, err := io.ReadFull(chunk.Reader(rd), chunkBuf)
// reduce length of buf
buf = buf[:chunk.Length]
n, err := io.ReadFull(chunk.Reader(rd), buf)
ok(b, err)
assert(b, uint(n) == chunk.Length, "invalid length: got %d, expected %d", n, chunk.Length)
_, err = key.Encrypt(chunkBuf, chunkBuf)
_, err = key.Encrypt(buf, buf)
ok(b, err)
}
@ -70,20 +70,19 @@ func BenchmarkChunkEncrypt(b *testing.B) {
defer teardownBackend(b, be)
key := setupKey(b, be, "geheim")
buf := restic.GetChunkBuf("BenchmarkChunkEncrypt")
b.ResetTimer()
b.SetBytes(int64(len(data)))
for i := 0; i < b.N; i++ {
benchmarkChunkEncrypt(b, rd, key)
}
benchmarkChunkEncrypt(b, buf, rd, key)
}
func benchmarkChunkEncryptP(b *testing.PB, rd interface {
io.ReadSeeker
io.ReaderAt
}, key *restic.Key) {
chunkBuf := make([]byte, restic.CiphertextExtension+chunker.MaxSize)
restic.FreeChunkBuf("BenchmarkChunkEncrypt", buf)
}
func benchmarkChunkEncryptP(b *testing.PB, buf []byte, rd Rdr, key *restic.Key) {
ch := restic.GetChunker("BenchmarkChunkEncryptP")
rd.Seek(0, 0)
ch.Reset(rd)
@ -95,9 +94,9 @@ func benchmarkChunkEncryptP(b *testing.PB, rd interface {
}
// reduce length of chunkBuf
chunkBuf = chunkBuf[:chunk.Length]
io.ReadFull(chunk.Reader(rd), chunkBuf)
key.Encrypt(chunkBuf, chunkBuf)
buf = buf[:chunk.Length]
io.ReadFull(chunk.Reader(rd), buf)
key.Encrypt(buf, buf)
}
restic.FreeChunker("BenchmarkChunkEncryptP", ch)
@ -110,15 +109,19 @@ func BenchmarkChunkEncryptParallel(b *testing.B) {
data := get_random(23, 10<<20) // 10MiB
buf := restic.GetChunkBuf("BenchmarkChunkEncryptParallel")
b.ResetTimer()
b.SetBytes(int64(len(data)))
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
rd := bytes.NewReader(data)
benchmarkChunkEncryptP(pb, rd, key)
benchmarkChunkEncryptP(pb, buf, rd, key)
}
})
restic.FreeChunkBuf("BenchmarkChunkEncryptParallel", buf)
}
func BenchmarkArchiveDirectory(b *testing.B) {