Commit 11a9896f authored by Eric Myhre's avatar Eric Myhre

cleanup/standardize more of the spec tests.

parent d563e4d3
......@@ -86,12 +86,12 @@ func BenchmarkMap25nGenericMapIterationSimpleKeys(b *testing.B) {
// benchmarks covering encoding -->
func BenchmarkUnmarshalMapStrInt_3n(b *testing.B) {
tests.SpecBenchmarkUnmarshalMapStrInt_3n(b, NodeBuilder())
func BenchmarkSpec_Marshal_Map3StrInt(b *testing.B) {
tests.BenchmarkSpec_Marshal_Map3StrInt(b, NodeBuilder())
}
func BenchmarkMarshalMapStrInt_3n(b *testing.B) {
tests.SpecBenchmarkMarshalMapStrInt_3n(b, NodeBuilder())
func BenchmarkSpec_Unmarshal_Map3StrInt(b *testing.B) {
tests.BenchmarkSpec_Unmarshal_Map3StrInt(b, NodeBuilder())
}
// benchmarks covering traversal -->
......
......@@ -8,6 +8,7 @@ import (
ipld "github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/encoding"
"github.com/ipld/go-ipld-prime/tests/corpus"
)
// All of the marshalling and unmarshalling benchmark specs use JSON.
......@@ -19,18 +20,17 @@ import (
// - we can make direct comparisons to the standard library json marshalling
// and unmarshalling, thus having a back-of-the-envelope baseline to compare.
func SpecBenchmarkMarshalMapStrInt_3n(b *testing.B, nb ipld.NodeBuilder) {
n, err := encoding.Unmarshal(nb, refmtjson.NewDecoder(bytes.NewBufferString(`{"whee":1,"woot":2,"waga":3}`)))
if err != nil {
panic(err)
}
func BenchmarkSpec_Marshal_Map3StrInt(b *testing.B, nb ipld.NodeBuilder) {
node := mustNodeFromJsonString(nb, corpus.Map3StrInt())
b.ResetTimer()
var err error
for i := 0; i < b.N; i++ {
var buf bytes.Buffer
err = encoding.Marshal(n, refmtjson.NewEncoder(&buf, refmtjson.EncodeOptions{}))
err = encoding.Marshal(node, refmtjson.NewEncoder(&buf, refmtjson.EncodeOptions{}))
sink = buf
}
if err != nil {
panic(err)
b.Fatalf("marshal errored: %s", err)
}
}
package tests
import (
"bytes"
"fmt"
"testing"
refmtjson "github.com/polydawn/refmt/json"
ipld "github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/encoding"
"github.com/ipld/go-ipld-prime/must"
"github.com/ipld/go-ipld-prime/tests/corpus"
"github.com/ipld/go-ipld-prime/traversal"
"github.com/ipld/go-ipld-prime/traversal/selector"
)
func mustNodeFromJsonString(nb ipld.NodeBuilder, str string) ipld.Node {
return must.Node(encoding.Unmarshal(nb, refmtjson.NewDecoder(bytes.NewBufferString(str))))
}
func mustSelectorFromJsonString(nb ipld.NodeBuilder, str string) selector.Selector {
// Needing an 'nb' parameter here is sort of off-topic, to be honest.
// Someday the selector package will probably contain codegen'd nodes of its own schema, and we'll use those unconditionally.
// For now... we'll just use whatever node you're already testing, because it oughta work
// (and because it avoids hardcoding any other implementation that might cause import cycle funtimes.).
seldefn := mustNodeFromJsonString(nb, str)
sel, err := selector.ParseSelector(seldefn)
must.NotError(err)
return sel
}
func BenchmarkSpec_Walk_Map3StrInt(b *testing.B, nb ipld.NodeBuilder) {
node := mustNodeFromJsonString(nb, corpus.Map3StrInt())
sel := mustSelectorFromJsonString(nb, `{"a":{">":{".":{}}}}`)
......
......@@ -8,6 +8,7 @@ import (
ipld "github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/encoding"
"github.com/ipld/go-ipld-prime/tests/corpus"
)
// All of the marshalling and unmarshalling benchmark specs use JSON.
......@@ -21,12 +22,15 @@ import (
var sink interface{}
func SpecBenchmarkUnmarshalMapStrInt_3n(b *testing.B, nb ipld.NodeBuilder) {
func BenchmarkSpec_Unmarshal_Map3StrInt(b *testing.B, nb ipld.NodeBuilder) {
msg := corpus.Map3StrInt()
b.ResetTimer()
var err error
for i := 0; i < b.N; i++ {
sink, err = encoding.Unmarshal(nb, refmtjson.NewDecoder(bytes.NewBufferString(`{"whee":1,"woot":2,"waga":3}`)))
sink, err = encoding.Unmarshal(nb, refmtjson.NewDecoder(bytes.NewBufferString(msg)))
}
if err != nil {
panic(err)
b.Fatalf("unmarshal errored: %s", err)
}
}
package tests
import (
"bytes"
refmtjson "github.com/polydawn/refmt/json"
ipld "github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/encoding"
"github.com/ipld/go-ipld-prime/must"
"github.com/ipld/go-ipld-prime/traversal/selector"
)
func mustNodeFromJsonString(nb ipld.NodeBuilder, str string) ipld.Node {
return must.Node(encoding.Unmarshal(nb, refmtjson.NewDecoder(bytes.NewBufferString(str))))
}
func mustSelectorFromJsonString(nb ipld.NodeBuilder, str string) selector.Selector {
// Needing an 'nb' parameter here is sort of off-topic, to be honest.
// Someday the selector package will probably contain codegen'd nodes of its own schema, and we'll use those unconditionally.
// For now... we'll just use whatever node you're already testing, because it oughta work
// (and because it avoids hardcoding any other implementation that might cause import cycle funtimes.).
seldefn := mustNodeFromJsonString(nb, str)
sel, err := selector.ParseSelector(seldefn)
must.NotError(err)
return sel
}
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