forked from TrueCloudLab/restic
Merge pull request #2760 from greatroar/backend-benchmark
Fix backend benchmarks + a micro-optimization
This commit is contained in:
commit
212607dc8a
2 changed files with 25 additions and 31 deletions
|
@ -48,17 +48,17 @@ func (s *Suite) BenchmarkLoadFile(t *testing.B) {
|
|||
n, ierr = io.ReadFull(rd, buf)
|
||||
return ierr
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
t.StopTimer()
|
||||
switch {
|
||||
case err != nil:
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if n != length {
|
||||
case n != length:
|
||||
t.Fatalf("wrong number of bytes read: want %v, got %v", length, n)
|
||||
}
|
||||
|
||||
if !bytes.Equal(data, buf) {
|
||||
case !bytes.Equal(data, buf):
|
||||
t.Fatalf("wrong bytes returned")
|
||||
}
|
||||
t.StartTimer()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,18 +85,17 @@ func (s *Suite) BenchmarkLoadPartialFile(t *testing.B) {
|
|||
n, ierr = io.ReadFull(rd, buf)
|
||||
return ierr
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
t.StopTimer()
|
||||
switch {
|
||||
case err != nil:
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if n != testLength {
|
||||
case n != testLength:
|
||||
t.Fatalf("wrong number of bytes read: want %v, got %v", testLength, n)
|
||||
}
|
||||
|
||||
if !bytes.Equal(data[:testLength], buf) {
|
||||
case !bytes.Equal(data[:testLength], buf):
|
||||
t.Fatalf("wrong bytes returned")
|
||||
}
|
||||
|
||||
t.StartTimer()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,17 +123,17 @@ func (s *Suite) BenchmarkLoadPartialFileOffset(t *testing.B) {
|
|||
n, ierr = io.ReadFull(rd, buf)
|
||||
return ierr
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
t.StopTimer()
|
||||
switch {
|
||||
case err != nil:
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if n != testLength {
|
||||
case n != testLength:
|
||||
t.Fatalf("wrong number of bytes read: want %v, got %v", testLength, n)
|
||||
}
|
||||
|
||||
if !bytes.Equal(data[testOffset:testOffset+testLength], buf) {
|
||||
case !bytes.Equal(data[testOffset:testOffset+testLength], buf):
|
||||
t.Fatalf("wrong bytes returned")
|
||||
}
|
||||
t.StartTimer()
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,19 +32,14 @@ func LoadAll(ctx context.Context, buf []byte, be restic.Backend, h restic.Handle
|
|||
|
||||
// LimitedReadCloser wraps io.LimitedReader and exposes the Close() method.
|
||||
type LimitedReadCloser struct {
|
||||
io.ReadCloser
|
||||
io.Reader
|
||||
io.Closer
|
||||
io.LimitedReader
|
||||
}
|
||||
|
||||
// Read reads data from the limited reader.
|
||||
func (l *LimitedReadCloser) Read(p []byte) (int, error) {
|
||||
return l.Reader.Read(p)
|
||||
}
|
||||
|
||||
// LimitReadCloser returns a new reader wraps r in an io.LimitReader, but also
|
||||
// LimitReadCloser returns a new reader wraps r in an io.LimitedReader, but also
|
||||
// exposes the Close() method.
|
||||
func LimitReadCloser(r io.ReadCloser, n int64) *LimitedReadCloser {
|
||||
return &LimitedReadCloser{ReadCloser: r, Reader: io.LimitReader(r, n)}
|
||||
return &LimitedReadCloser{Closer: r, LimitedReader: io.LimitedReader{R: r, N: n}}
|
||||
}
|
||||
|
||||
// DefaultLoad implements Backend.Load using lower-level openReader func
|
||||
|
|
Loading…
Reference in a new issue