mirror of
https://github.com/octoleo/restic.git
synced 2024-12-23 03:18:55 +00:00
Fix benchmarks for ChunkEncrypt
This commit is contained in:
parent
af57fb86d7
commit
43ae0b69ab
@ -30,12 +30,12 @@ func randomReader(seed, size int) *bytes.Reader {
|
|||||||
|
|
||||||
const bufSize = chunker.MiB
|
const bufSize = chunker.MiB
|
||||||
|
|
||||||
func benchmarkChunkEncrypt(b testing.TB, rd interface {
|
type Rdr interface {
|
||||||
io.ReadSeeker
|
io.ReadSeeker
|
||||||
io.ReaderAt
|
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")
|
ch := restic.GetChunker("BenchmarkChunkEncrypt")
|
||||||
rd.Seek(0, 0)
|
rd.Seek(0, 0)
|
||||||
ch.Reset(rd)
|
ch.Reset(rd)
|
||||||
@ -49,13 +49,13 @@ func benchmarkChunkEncrypt(b testing.TB, rd interface {
|
|||||||
|
|
||||||
ok(b, err)
|
ok(b, err)
|
||||||
|
|
||||||
// reduce length of chunkBuf
|
// reduce length of buf
|
||||||
chunkBuf = chunkBuf[:chunk.Length]
|
buf = buf[:chunk.Length]
|
||||||
n, err := io.ReadFull(chunk.Reader(rd), chunkBuf)
|
n, err := io.ReadFull(chunk.Reader(rd), buf)
|
||||||
ok(b, err)
|
ok(b, err)
|
||||||
assert(b, uint(n) == chunk.Length, "invalid length: got %d, expected %d", n, chunk.Length)
|
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)
|
ok(b, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,20 +70,19 @@ func BenchmarkChunkEncrypt(b *testing.B) {
|
|||||||
defer teardownBackend(b, be)
|
defer teardownBackend(b, be)
|
||||||
key := setupKey(b, be, "geheim")
|
key := setupKey(b, be, "geheim")
|
||||||
|
|
||||||
|
buf := restic.GetChunkBuf("BenchmarkChunkEncrypt")
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
b.SetBytes(int64(len(data)))
|
b.SetBytes(int64(len(data)))
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
benchmarkChunkEncrypt(b, rd, key)
|
benchmarkChunkEncrypt(b, buf, rd, key)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchmarkChunkEncryptP(b *testing.PB, rd interface {
|
restic.FreeChunkBuf("BenchmarkChunkEncrypt", buf)
|
||||||
io.ReadSeeker
|
}
|
||||||
io.ReaderAt
|
|
||||||
}, key *restic.Key) {
|
|
||||||
chunkBuf := make([]byte, restic.CiphertextExtension+chunker.MaxSize)
|
|
||||||
|
|
||||||
|
func benchmarkChunkEncryptP(b *testing.PB, buf []byte, rd Rdr, key *restic.Key) {
|
||||||
ch := restic.GetChunker("BenchmarkChunkEncryptP")
|
ch := restic.GetChunker("BenchmarkChunkEncryptP")
|
||||||
rd.Seek(0, 0)
|
rd.Seek(0, 0)
|
||||||
ch.Reset(rd)
|
ch.Reset(rd)
|
||||||
@ -95,9 +94,9 @@ func benchmarkChunkEncryptP(b *testing.PB, rd interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// reduce length of chunkBuf
|
// reduce length of chunkBuf
|
||||||
chunkBuf = chunkBuf[:chunk.Length]
|
buf = buf[:chunk.Length]
|
||||||
io.ReadFull(chunk.Reader(rd), chunkBuf)
|
io.ReadFull(chunk.Reader(rd), buf)
|
||||||
key.Encrypt(chunkBuf, chunkBuf)
|
key.Encrypt(buf, buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
restic.FreeChunker("BenchmarkChunkEncryptP", ch)
|
restic.FreeChunker("BenchmarkChunkEncryptP", ch)
|
||||||
@ -110,15 +109,19 @@ func BenchmarkChunkEncryptParallel(b *testing.B) {
|
|||||||
|
|
||||||
data := get_random(23, 10<<20) // 10MiB
|
data := get_random(23, 10<<20) // 10MiB
|
||||||
|
|
||||||
|
buf := restic.GetChunkBuf("BenchmarkChunkEncryptParallel")
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
b.SetBytes(int64(len(data)))
|
b.SetBytes(int64(len(data)))
|
||||||
|
|
||||||
b.RunParallel(func(pb *testing.PB) {
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
for pb.Next() {
|
for pb.Next() {
|
||||||
rd := bytes.NewReader(data)
|
rd := bytes.NewReader(data)
|
||||||
benchmarkChunkEncryptP(pb, rd, key)
|
benchmarkChunkEncryptP(pb, buf, rd, key)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
restic.FreeChunkBuf("BenchmarkChunkEncryptParallel", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkArchiveDirectory(b *testing.B) {
|
func BenchmarkArchiveDirectory(b *testing.B) {
|
||||||
|
Loading…
Reference in New Issue
Block a user