1
0
Fork 0
forked from mirrors/tar-split

tar/asm: basic benchmark on disasm/asm of testdata

```
PASS
BenchmarkAsm-4         5         238968475 ns/op        66841059 B/op       2449 allocs/op
ok      _/home/vbatts/src/vb/tar-split/tar/asm  2.267s
```

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2015-12-02 14:36:02 -05:00
parent 026e78012b
commit 19b7e22058

View file

@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"hash/crc64" "hash/crc64"
"io" "io"
"io/ioutil"
"os" "os"
"testing" "testing"
@ -129,8 +130,7 @@ func TestTarStreamMangledGetterPutter(t *testing.T) {
} }
} }
func TestTarStream(t *testing.T) { var testCases = []struct {
testCases := []struct {
path string path string
expectedSHA1Sum string expectedSHA1Sum string
expectedSize int64 expectedSize int64
@ -141,6 +141,8 @@ func TestTarStream(t *testing.T) {
{"./testdata/iso-8859.tar.gz", "ddafa51cb03c74ec117ab366ee2240d13bba1ec3", 10240}, {"./testdata/iso-8859.tar.gz", "ddafa51cb03c74ec117ab366ee2240d13bba1ec3", 10240},
} }
func TestTarStream(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
fh, err := os.Open(tc.path) fh, err := os.Open(tc.path)
if err != nil { if err != nil {
@ -201,3 +203,52 @@ func TestTarStream(t *testing.T) {
} }
} }
} }
func BenchmarkAsm(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, tc := range testCases {
func() {
fh, err := os.Open(tc.path)
if err != nil {
b.Fatal(err)
}
defer fh.Close()
gzRdr, err := gzip.NewReader(fh)
if err != nil {
b.Fatal(err)
}
defer gzRdr.Close()
// Setup where we'll store the metadata
w := bytes.NewBuffer([]byte{})
sp := storage.NewJSONPacker(w)
fgp := storage.NewBufferFileGetPutter()
// wrap the disassembly stream
tarStream, err := NewInputTarStream(gzRdr, sp, fgp)
if err != nil {
b.Fatal(err)
}
// read it all to the bit bucket
i1, err := io.Copy(ioutil.Discard, tarStream)
if err != nil {
b.Fatal(err)
}
r := bytes.NewBuffer(w.Bytes())
sup := storage.NewJSONUnpacker(r)
// and reuse the fgp that we Put the payloads to.
rc := NewOutputTarStream(fgp, sup)
i2, err := io.Copy(ioutil.Discard, rc)
if err != nil {
b.Fatal(err)
}
if i1 != i2 {
b.Errorf("%s: input(%d) and ouput(%d) byte count didn't match", tc.path, i1, i2)
}
}()
}
}
}