Skip to content

Commit

Permalink
eskip: add gob unmarshal benchmark (#2877)
Browse files Browse the repository at this point in the history
```
$ benchstat -col .name <(go test ./eskip -run=NONE -bench='BenchmarkGobUnmarshal|BenchmarkParse$' -count=10)
goos: linux
goarch: amd64
pkg: github.com/zalando/skipper/eskip
cpu: Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz
    │    Parse    │            GobUnmarshal            │
    │   sec/op    │   sec/op     vs base               │
*-8   238.8m ± 1%   227.9m ± 1%  -4.57% (p=0.000 n=10)

    │    Parse     │            GobUnmarshal             │
    │   bytes/op   │   bytes/op    vs base               │
*-8   15.99Mi ± 0%   17.05Mi ± 0%  +6.62% (p=0.000 n=10)

    │    Parse     │             GobUnmarshal             │
    │     B/op     │     B/op      vs base                │
*-8   49.02Mi ± 0%   70.53Mi ± 0%  +43.88% (p=0.000 n=10)

    │    Parse    │            GobUnmarshal            │
    │  allocs/op  │  allocs/op   vs base               │
*-8   1.080M ± 0%   1.020M ± 0%  -5.52% (p=0.000 n=10)
```

Signed-off-by: Alexander Yastrebov <[email protected]>
  • Loading branch information
AlexanderYastrebov authored Jan 19, 2024
1 parent 80234b7 commit 568a5d0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions eskip/eskip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,8 @@ func BenchmarkParse(b *testing.B) {

b.ReportAllocs()
b.ResetTimer()
b.ReportMetric(float64(len(benchmarkRoutes10k)), "bytes/op")

for i := 0; i < b.N; i++ {
_, _ = Parse(benchmarkRoutes10k)
}
Expand Down
37 changes: 37 additions & 0 deletions eskip/gob_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package eskip

import (
"bytes"
"encoding/gob"
"reflect"
"testing"
)

func BenchmarkGobUnmarshal(b *testing.B) {
var buf bytes.Buffer

in := MustParse(benchmarkRoutes10k)
err := gob.NewEncoder(&buf).Encode(in)
if err != nil {
b.Fatal(err)
}

content := buf.Bytes()

var out []*Route
if err := gob.NewDecoder(bytes.NewReader(content)).Decode(&out); err != nil {
b.Fatal(err)
}

if !reflect.DeepEqual(in, out) {
b.Fatal("input does not match output")
}

b.ReportAllocs()
b.ResetTimer()
b.ReportMetric(float64(len(content)), "bytes/op")

for i := 0; i < b.N; i++ {
_ = gob.NewDecoder(bytes.NewReader(content)).Decode(&out)
}
}

0 comments on commit 568a5d0

Please sign in to comment.