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

Further reduce redundant setup.

In the process, noticed we're using the test subject nodebuilder for
part of the selector setup too... which is... well, it's not wrong,
per se, but it's certainly tangental.  I don't see any good way to
avoid it though, so, there's now just a comment about this fact.
parent 2be85512
...@@ -14,11 +14,23 @@ import ( ...@@ -14,11 +14,23 @@ import (
"github.com/ipld/go-ipld-prime/traversal/selector" "github.com/ipld/go-ipld-prime/traversal/selector"
) )
func SpecBenchmarkWalkMapStrInt_3n(b *testing.B, nb ipld.NodeBuilder) { func mustNodeFromJsonString(nb ipld.NodeBuilder, str string) ipld.Node {
n := must.Node(encoding.Unmarshal(nb, refmtjson.NewDecoder(bytes.NewBufferString(corpus.Map3StrInt())))) return must.Node(encoding.Unmarshal(nb, refmtjson.NewDecoder(bytes.NewBufferString(str))))
seldefn := must.Node(encoding.Unmarshal(nb, refmtjson.NewDecoder(bytes.NewBufferString(`{"a":{">":{".":{}}}}`)))) }
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) sel, err := selector.ParseSelector(seldefn)
must.NotError(err) must.NotError(err)
return sel
}
func SpecBenchmarkWalkMapStrInt_3n(b *testing.B, nb ipld.NodeBuilder) {
n := mustNodeFromJsonString(nb, corpus.Map3StrInt())
sel := mustSelectorFromJsonString(nb, `{"a":{">":{".":{}}}}`)
b.ResetTimer() b.ResetTimer()
var visitCountSanityCheck int var visitCountSanityCheck int
......
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