Skip to content

Commit

Permalink
Add benchmark for snapshot streams
Browse files Browse the repository at this point in the history
  • Loading branch information
hansmi committed Nov 22, 2022
1 parent bb3315a commit 701971f
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions internal/snapshotstream/stream_throughput_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package snapshotstream

import (
"bytes"
"crypto/rand"
"testing"
"testing/fstest"

"github.com/hansmi/prombackup/api"
)

func BenchmarkStreamWriteTo(b *testing.B) {
const fileSize = 128 * 1024 * 1024

fileData := make([]byte, fileSize)

if _, err := rand.Read(fileData); err != nil {
b.Fatalf("Read() failed: %v", err)
}

root := fstest.MapFS{
"file": {
Data: fileData,
},
}

s, err := New(Options{
Name: "stream",
Root: root,
Format: api.ArchiveTar,
})
if err != nil {
b.Fatalf("New() failed: %v", err)
}

var buf bytes.Buffer

buf.Grow(fileSize)

b.SetBytes(fileSize)
b.ResetTimer()

for i := 0; i < b.N; i++ {
if err := s.WriteTo(&buf); err != nil {
b.Errorf("WriteTo() failed: %v", err)
}

buf.Reset()
}
}

0 comments on commit 701971f

Please sign in to comment.