Commit 3cdd0cbb authored by Eric Myhre's avatar Eric Myhre

Quick null marshall benchmark.

This one takes 489ns/op... indicating that indeed 54.6% of the time
spent by the real marshalling of json is on the json details.

I would've thought this would be even larger, actually.  Hm.

May keep this 'null' marshaller.  Not sure.  Does it tell a useful
story, or tell a story clearer than doing the same thing with json?
Signed-off-by: default avatarEric Myhre <hash@exultant.us>
parent d3ddbfee
...@@ -38,4 +38,6 @@ func BenchmarkUnmarshalMapStrInt_3n(b *testing.B) { ...@@ -38,4 +38,6 @@ func BenchmarkUnmarshalMapStrInt_3n(b *testing.B) {
func BenchmarkMarshalMapStrInt_3n(b *testing.B) { func BenchmarkMarshalMapStrInt_3n(b *testing.B) {
tests.SpecBenchmarkMarshalMapStrInt_3n(b, Style__Map{}) tests.SpecBenchmarkMarshalMapStrInt_3n(b, Style__Map{})
} }
func BenchmarkMarshalToNullMapStrInt_3n(b *testing.B) {
tests.SpecBenchmarkMarshalToNullMapStrInt_3n(b, Style__Map{})
}
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"testing" "testing"
refmtjson "github.com/polydawn/refmt/json" refmtjson "github.com/polydawn/refmt/json"
"github.com/polydawn/refmt/tok"
ipld "github.com/ipld/go-ipld-prime/_rsrch/nodesolution" ipld "github.com/ipld/go-ipld-prime/_rsrch/nodesolution"
"github.com/ipld/go-ipld-prime/_rsrch/nodesolution/codec" "github.com/ipld/go-ipld-prime/_rsrch/nodesolution/codec"
...@@ -35,3 +36,26 @@ func SpecBenchmarkMarshalMapStrInt_3n(b *testing.B, ns ipld.NodeStyle) { ...@@ -35,3 +36,26 @@ func SpecBenchmarkMarshalMapStrInt_3n(b *testing.B, ns ipld.NodeStyle) {
panic(err) panic(err)
} }
} }
func SpecBenchmarkMarshalToNullMapStrInt_3n(b *testing.B, ns ipld.NodeStyle) {
nb := ns.NewBuilder()
must.NotError(codec.Unmarshal(nb, refmtjson.NewDecoder(bytes.NewBufferString(`{"whee":1,"woot":2,"waga":3}`))))
n := nb.Build()
b.ResetTimer()
var err error
encoder := &nullTokenSink{}
for i := 0; i < b.N; i++ {
var buf bytes.Buffer
err = codec.Marshal(n, encoder)
sink = buf
}
if err != nil {
panic(err)
}
}
type nullTokenSink struct{}
func (nullTokenSink) Step(_ *tok.Token) (bool, error) {
return false, nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment