Commit bed1eff1 authored by Eric Myhre's avatar Eric Myhre

Finally I can add this: traversal benchmarks.

Lots of import cycle fixing was necessary to get here, which was an
unpleasant surprise at the start of the day... but lots of things are
better off now, so it was highly worth it.
parent 9d87c836
......@@ -94,6 +94,12 @@ func BenchmarkMarshalMapStrInt_3n(b *testing.B) {
tests.SpecBenchmarkMarshalMapStrInt_3n(b, NodeBuilder())
}
// benchmarks covering traversal -->
func BenchmarkWalkMapStrInt_3n(b *testing.B) {
tests.SpecBenchmarkWalkMapStrInt_3n(b, NodeBuilder())
}
// copy of helper functions from must package, because import cycles, sigh -->
func mustNotError(e error) {
......
package tests
import (
"bytes"
"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/tests/corpus"
"github.com/ipld/go-ipld-prime/traversal"
"github.com/ipld/go-ipld-prime/traversal/selector"
)
func SpecBenchmarkWalkMapStrInt_3n(b *testing.B, nb ipld.NodeBuilder) {
n, err := encoding.Unmarshal(nb, refmtjson.NewDecoder(bytes.NewBufferString(corpus.Map3StrInt())))
if err != nil {
panic(err)
}
seldefn, err := encoding.Unmarshal(nb, refmtjson.NewDecoder(bytes.NewBufferString(`{"a":{">":{".":{}}}}`)))
if err != nil {
panic(err)
}
sel, err := selector.ParseSelector(seldefn)
if err != nil {
panic(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
traversal.WalkMatching(n, sel, func(tp traversal.Progress, n ipld.Node) error {
return nil // no need to do anything here; just care about exercising the walk internals.
})
}
}
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