1
0
Fork 1
mirror of https://github.com/vbatts/tar-split.git synced 2024-12-18 19:46:29 +00:00

Merge pull request #25 from vbatts/bench

tar/storage: adding Getter Putter benchmark
This commit is contained in:
Vincent Batts 2015-12-01 14:37:10 -06:00
commit 93666d5824

View file

@ -4,6 +4,8 @@ import (
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"io" "io"
"io/ioutil"
"os"
"testing" "testing"
) )
@ -159,5 +161,58 @@ func TestGzip(t *testing.T) {
if len(entries) != len(e) { if len(entries) != len(e) {
t.Errorf("expected %d entries, got %d", len(e), len(entries)) t.Errorf("expected %d entries, got %d", len(e), len(entries))
} }
}
func BenchmarkGetPut(b *testing.B) {
e := []Entry{
Entry{
Type: SegmentType,
Payload: []byte("how"),
},
Entry{
Type: SegmentType,
Payload: []byte("y'all"),
},
Entry{
Type: FileType,
Name: "./hurr.txt",
Payload: []byte("deadbeef"),
},
Entry{
Type: SegmentType,
Payload: []byte("doin"),
},
}
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
func() {
fh, err := ioutil.TempFile("", "tar-split.")
if err != nil {
b.Fatal(err)
}
defer os.Remove(fh.Name())
defer fh.Close()
jp := NewJSONPacker(fh)
for i := range e {
if _, err := jp.AddEntry(e[i]); err != nil {
b.Fatal(err)
}
}
fh.Sync()
up := NewJSONUnpacker(fh)
for {
_, err := up.Next()
if err != nil {
if err == io.EOF {
break
}
b.Fatal(err)
}
}
}()
}
})
} }