tests: Add benchmark for Save

This commit is contained in:
Alexander Neumann 2017-05-13 23:04:30 +02:00
parent 8fc25cc567
commit 5b8131e2d3
2 changed files with 30 additions and 0 deletions

View File

@ -144,3 +144,32 @@ func BackendBenchmarkLoadPartialFileOffset(t *testing.B, s *Suite) {
}
}
func BackendBenchmarkSave(t *testing.B, s *Suite) {
be := s.open(t)
defer s.close(t, be)
length := 1<<24 + 2123
data := test.Random(23, length)
id := restic.Hash(data)
handle := restic.Handle{Type: restic.DataFile, Name: id.String()}
rd := bytes.NewReader(data)
t.SetBytes(int64(length))
t.ResetTimer()
for i := 0; i < t.N; i++ {
if _, err := rd.Seek(0, 0); err != nil {
t.Fatal(err)
}
if err := be.Save(handle, rd); err != nil {
t.Fatal(err)
}
if err := be.Remove(handle); err != nil {
t.Fatal(err)
}
}
}

View File

@ -27,4 +27,5 @@ var benchmarkFunctions = []struct {
{"LoadFile", BackendBenchmarkLoadFile},
{"LoadPartialFile", BackendBenchmarkLoadPartialFile},
{"LoadPartialFileOffset", BackendBenchmarkLoadPartialFileOffset},
{"Save", BackendBenchmarkSave},
}