mirror of
https://github.com/restic/restic.git
synced 2026-09-15 08:47:57 +00:00
Re-use zlib writers to reduce memory usage
benchcmp:
benchmark old ns/op new ns/op delta
BenchmarkArchiveDirectory-4 29624960475 29511001504 -0.38%
BenchmarkSaveJSON-4 379833 225609 -40.60%
benchmark old allocs new allocs delta
BenchmarkArchiveDirectory-4 546736 540642 -1.11%
BenchmarkSaveJSON-4 150 126 -16.00%
benchmark old bytes new bytes delta
BenchmarkArchiveDirectory-4 1372476952 438519336 -68.05%
BenchmarkSaveJSON-4 1462773 9087 -99.38%
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package restic_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic"
|
||||
"github.com/restic/restic/backend"
|
||||
)
|
||||
|
||||
type testJSONStruct struct {
|
||||
Foo uint32
|
||||
Bar string
|
||||
Baz []byte
|
||||
}
|
||||
|
||||
var serverTests = []testJSONStruct{
|
||||
testJSONStruct{Foo: 23, Bar: "Teststring", Baz: []byte("xx")},
|
||||
}
|
||||
|
||||
func TestSaveJSON(t *testing.T) {
|
||||
be := setupBackend(t)
|
||||
defer teardownBackend(t, be)
|
||||
key := setupKey(t, be, "geheim")
|
||||
server := restic.NewServerWithKey(be, key)
|
||||
|
||||
for _, obj := range serverTests {
|
||||
data, err := json.Marshal(obj)
|
||||
ok(t, err)
|
||||
data = append(data, '\n')
|
||||
h := sha256.Sum256(data)
|
||||
|
||||
blob, err := server.SaveJSON(backend.Tree, obj)
|
||||
ok(t, err)
|
||||
|
||||
assert(t, bytes.Equal(h[:], blob.ID),
|
||||
"TestSaveJSON: wrong plaintext ID: expected %02x, got %02x",
|
||||
h, blob.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSaveJSON(t *testing.B) {
|
||||
be := setupBackend(t)
|
||||
defer teardownBackend(t, be)
|
||||
key := setupKey(t, be, "geheim")
|
||||
server := restic.NewServerWithKey(be, key)
|
||||
|
||||
t.ResetTimer()
|
||||
//t.SetBytes(int64(size))
|
||||
|
||||
obj := serverTests[0]
|
||||
|
||||
data, err := json.Marshal(obj)
|
||||
ok(t, err)
|
||||
data = append(data, '\n')
|
||||
h := sha256.Sum256(data)
|
||||
|
||||
for i := 0; i < t.N; i++ {
|
||||
blob, err := server.SaveJSON(backend.Tree, obj)
|
||||
ok(t, err)
|
||||
|
||||
assert(t, bytes.Equal(h[:], blob.ID),
|
||||
"TestSaveJSON: wrong plaintext ID: expected %02x, got %02x",
|
||||
h, blob.ID)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user