diff --git a/eskip/eskip_test.go b/eskip/eskip_test.go index e675e7372b..b5b9d2df38 100644 --- a/eskip/eskip_test.go +++ b/eskip/eskip_test.go @@ -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) } diff --git a/eskip/gob_test.go b/eskip/gob_test.go new file mode 100644 index 0000000000..bb4c949894 --- /dev/null +++ b/eskip/gob_test.go @@ -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) + } +}