mirror of
https://github.com/restic/restic.git
synced 2025-08-20 08:57:29 +00:00
Decrease allocation rate in internal/pack
internal/repository benchmark results: name old time/op new time/op delta PackerManager-8 179ms ± 1% 181ms ± 1% +0.78% (p=0.009 n=10+10) name old speed new speed delta PackerManager-8 294MB/s ± 1% 292MB/s ± 1% -0.77% (p=0.009 n=10+10) name old alloc/op new alloc/op delta PackerManager-8 91.3kB ± 0% 72.2kB ± 0% -20.92% (p=0.000 n=9+7) name old allocs/op new allocs/op delta PackerManager-8 1.38k ± 0% 0.76k ± 0% -45.20% (p=0.000 n=10+7)
This commit is contained in:

committed by
Alexander Neumann

parent
9a8a2cae4c
commit
ab2b7d7f9a
@@ -7,9 +7,44 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/internal/crypto"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func TestParseHeaderEntry(t *testing.T) {
|
||||
h := headerEntry{
|
||||
Type: 0, // Blob.
|
||||
Length: 100,
|
||||
}
|
||||
for i := range h.ID {
|
||||
h.ID[i] = byte(i)
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
_ = binary.Write(buf, binary.LittleEndian, &h)
|
||||
|
||||
b, err := parseHeaderEntry(buf.Bytes())
|
||||
rtest.OK(t, err)
|
||||
rtest.Equals(t, restic.DataBlob, b.Type)
|
||||
t.Logf("%v %v", h.ID, b.ID)
|
||||
rtest.Assert(t, bytes.Equal(h.ID[:], b.ID[:]), "id mismatch")
|
||||
rtest.Equals(t, uint(h.Length), b.Length)
|
||||
|
||||
h.Type = 0xae
|
||||
buf.Reset()
|
||||
_ = binary.Write(buf, binary.LittleEndian, &h)
|
||||
|
||||
b, err = parseHeaderEntry(buf.Bytes())
|
||||
rtest.Assert(t, err != nil, "no error for invalid type")
|
||||
|
||||
h.Type = 0
|
||||
buf.Reset()
|
||||
_ = binary.Write(buf, binary.LittleEndian, &h)
|
||||
|
||||
b, err = parseHeaderEntry(buf.Bytes()[:entrySize-1])
|
||||
rtest.Assert(t, err != nil, "no error for short input")
|
||||
}
|
||||
|
||||
type countingReaderAt struct {
|
||||
delegate io.ReaderAt
|
||||
invocationCount int
|
||||
|
Reference in New Issue
Block a user