Commit ffc140e7 authored by Eric Myhre's avatar Eric Myhre

Entersen some test and benchmark setup.

I'm wary as heck at introducing any amount of abstraction in
benchmarks, because sometimes, it starts to foment lies in the
most unexpected ways.  However, I did several fairly long runs
with and without this contraction, and they seem to vary on the
order of single nanoseconds -- while the noise between test runs
varies by a few dozen.  So, this appears to be safe to move on.
parent 80173ce2
......@@ -5,6 +5,7 @@ import (
"testing"
ipld "github.com/ipld/go-ipld-prime/_rsrch/nodesolution"
"github.com/ipld/go-ipld-prime/must"
)
var sink interface{}
......@@ -22,9 +23,7 @@ func BenchmarkMap3nBaselineNativeMapAssignSimpleKeys(b *testing.B) {
func BenchmarkMap3nBaselineJsonUnmarshalMapSimpleKeys(b *testing.B) {
for i := 0; i < b.N; i++ {
var x = make(map[string]int, 3)
if err := json.Unmarshal([]byte(`{"whee":1,"woot":2,"waga":3}`), &x); err != nil {
panic(err)
}
must.NotError(json.Unmarshal([]byte(`{"whee":1,"woot":2,"waga":3}`), &x))
sink = x
}
}
......@@ -37,27 +36,13 @@ func BenchmarkMap3nFeedGenericMapSimpleKeys(b *testing.B) {
if err != nil {
panic(err)
}
if err := ma.AssembleKey().AssignString("whee"); err != nil {
panic(err)
}
if err := ma.AssembleValue().AssignInt(1); err != nil {
panic(err)
}
if err := ma.AssembleKey().AssignString("woot"); err != nil {
panic(err)
}
if err := ma.AssembleValue().AssignInt(2); err != nil {
panic(err)
}
if err := ma.AssembleKey().AssignString("waga"); err != nil {
panic(err)
}
if err := ma.AssembleValue().AssignInt(3); err != nil {
panic(err)
}
if err := ma.Done(); err != nil {
panic(err)
}
must.NotError(ma.AssembleKey().AssignString("whee"))
must.NotError(ma.AssembleValue().AssignInt(1))
must.NotError(ma.AssembleKey().AssignString("woot"))
must.NotError(ma.AssembleValue().AssignInt(2))
must.NotError(ma.AssembleKey().AssignString("waga"))
must.NotError(ma.AssembleValue().AssignInt(3))
must.NotError(ma.Done())
if n, err := nb.Build(); err != nil {
panic(err)
} else {
......@@ -74,27 +59,13 @@ func BenchmarkMap3nFeedGennedMapSimpleKeys(b *testing.B) {
if err != nil {
panic(err)
}
if err := ma.AssembleKey().AssignString("whee"); err != nil {
panic(err)
}
if err := ma.AssembleValue().AssignInt(1); err != nil {
panic(err)
}
if err := ma.AssembleKey().AssignString("woot"); err != nil {
panic(err)
}
if err := ma.AssembleValue().AssignInt(2); err != nil {
panic(err)
}
if err := ma.AssembleKey().AssignString("waga"); err != nil {
panic(err)
}
if err := ma.AssembleValue().AssignInt(3); err != nil {
panic(err)
}
if err := ma.Done(); err != nil {
panic(err)
}
must.NotError(ma.AssembleKey().AssignString("whee"))
must.NotError(ma.AssembleValue().AssignInt(1))
must.NotError(ma.AssembleKey().AssignString("woot"))
must.NotError(ma.AssembleValue().AssignInt(2))
must.NotError(ma.AssembleKey().AssignString("waga"))
must.NotError(ma.AssembleValue().AssignInt(3))
must.NotError(ma.Done())
if n, err := nb.Build(); err != nil {
panic(err)
} else {
......@@ -114,27 +85,19 @@ func BenchmarkMap3nFeedGennedMapSimpleKeysDirectly(b *testing.B) {
if va, err := ma.AssembleDirectly("whee"); err != nil {
panic(err)
} else {
if err := va.AssignInt(1); err != nil {
panic(err)
}
must.NotError(va.AssignInt(1))
}
if va, err := ma.AssembleDirectly("woot"); err != nil {
panic(err)
} else {
if err := va.AssignInt(2); err != nil {
panic(err)
}
must.NotError(va.AssignInt(2))
}
if va, err := ma.AssembleDirectly("waga"); err != nil {
panic(err)
} else {
if err := va.AssignInt(3); err != nil {
panic(err)
}
}
if err := ma.Done(); err != nil {
panic(err)
must.NotError(va.AssignInt(3))
}
must.NotError(ma.Done())
if n, err := nb.Build(); err != nil {
panic(err)
} else {
......
......@@ -3,9 +3,10 @@ package impls
import (
"testing"
ipld "github.com/ipld/go-ipld-prime/_rsrch/nodesolution"
wish "github.com/warpfork/go-wish"
ipld "github.com/ipld/go-ipld-prime/_rsrch/nodesolution"
"github.com/ipld/go-ipld-prime/must"
)
func TestGennedMapIntValues(t *testing.T) {
......@@ -19,30 +20,14 @@ func CheckMaps(t *testing.T, ns ipld.NodeStyle) {
t.Run("map node, str:int, 3 entries", func(t *testing.T) {
nb := ns.NewBuilder()
ma, err := nb.BeginMap(3)
if err != nil {
panic(err)
}
if err := ma.AssembleKey().AssignString("whee"); err != nil {
panic(err)
}
if err := ma.AssembleValue().AssignInt(1); err != nil {
panic(err)
}
if err := ma.AssembleKey().AssignString("woot"); err != nil {
panic(err)
}
if err := ma.AssembleValue().AssignInt(2); err != nil {
panic(err)
}
if err := ma.AssembleKey().AssignString("waga"); err != nil {
panic(err)
}
if err := ma.AssembleValue().AssignInt(3); err != nil {
panic(err)
}
if err := ma.Done(); err != nil {
panic(err)
}
must.NotError(err)
must.NotError(ma.AssembleKey().AssignString("whee"))
must.NotError(ma.AssembleValue().AssignInt(1))
must.NotError(ma.AssembleKey().AssignString("woot"))
must.NotError(ma.AssembleValue().AssignInt(2))
must.NotError(ma.AssembleKey().AssignString("waga"))
must.NotError(ma.AssembleValue().AssignInt(3))
must.NotError(ma.Done())
n, err := nb.Build()
if err != nil {
wish.Require(t, err, wish.ShouldEqual, nil)
......
......@@ -21,6 +21,15 @@ import (
"github.com/ipld/go-ipld-prime/impl/typed"
)
// must.NotError simply panics if given an error.
// It helps turn multi-line code into one-liner code in situations where
// you simply don't care.
func NotError(e error) {
if e != nil {
panic(e)
}
}
// must.Node helps write pointfree/chainable-style code
// by taking a Node and an error and transforming any error into a panic.
//
......
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