From 5b8131e2d3096038c7d5e35b59ab410dd1121212 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 13 May 2017 23:04:30 +0200 Subject: [PATCH] tests: Add benchmark for Save --- src/restic/backend/test/benchmarks.go | 29 +++++++++++++++++++++++++++ src/restic/backend/test/funcs.go | 1 + 2 files changed, 30 insertions(+) diff --git a/src/restic/backend/test/benchmarks.go b/src/restic/backend/test/benchmarks.go index 42e94cfea..19831d96d 100644 --- a/src/restic/backend/test/benchmarks.go +++ b/src/restic/backend/test/benchmarks.go @@ -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) + } + } +} diff --git a/src/restic/backend/test/funcs.go b/src/restic/backend/test/funcs.go index 5058d1088..1f8a12a77 100644 --- a/src/restic/backend/test/funcs.go +++ b/src/restic/backend/test/funcs.go @@ -27,4 +27,5 @@ var benchmarkFunctions = []struct { {"LoadFile", BackendBenchmarkLoadFile}, {"LoadPartialFile", BackendBenchmarkLoadPartialFile}, {"LoadPartialFileOffset", BackendBenchmarkLoadPartialFileOffset}, + {"Save", BackendBenchmarkSave}, }