Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ld
go-ld-prime
Commits
11a9896f
Commit
11a9896f
authored
Feb 27, 2020
by
Eric Myhre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup/standardize more of the spec tests.
parent
d563e4d3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
34 deletions
+44
-34
impl/free/bench_test.go
impl/free/bench_test.go
+4
-4
tests/marshalBenchmarks.go
tests/marshalBenchmarks.go
+7
-7
tests/traversalBenchmarks.go
tests/traversalBenchmarks.go
+0
-20
tests/unmarshalBenchmarks.go
tests/unmarshalBenchmarks.go
+7
-3
tests/util.go
tests/util.go
+26
-0
No files found.
impl/free/bench_test.go
View file @
11a9896f
...
...
@@ -86,12 +86,12 @@ func BenchmarkMap25nGenericMapIterationSimpleKeys(b *testing.B) {
// benchmarks covering encoding -->
func
Benchmark
Unm
arshalMapStrInt
_3n
(
b
*
testing
.
B
)
{
tests
.
Spec
Benchmark
Unm
arshalMapStrInt
_3n
(
b
,
NodeBuilder
())
func
Benchmark
Spec_M
arshal
_
Map
3
StrInt
(
b
*
testing
.
B
)
{
tests
.
Benchmark
Spec_M
arshal
_
Map
3
StrInt
(
b
,
NodeBuilder
())
}
func
Benchmark
M
arshalMapStrInt
_3n
(
b
*
testing
.
B
)
{
tests
.
Spec
Benchmark
M
arshalMapStrInt
_3n
(
b
,
NodeBuilder
())
func
Benchmark
Spec_Unm
arshal
_
Map
3
StrInt
(
b
*
testing
.
B
)
{
tests
.
Benchmark
Spec_Unm
arshal
_
Map
3
StrInt
(
b
,
NodeBuilder
())
}
// benchmarks covering traversal -->
...
...
tests/marshalBenchmarks.go
View file @
11a9896f
...
...
@@ -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
(
n
ode
,
refmtjson
.
NewEncoder
(
&
buf
,
refmtjson
.
EncodeOptions
{}))
sink
=
buf
}
if
err
!=
nil
{
panic
(
err
)
b
.
Fatalf
(
"marshal errored: %s"
,
err
)
}
}
tests/traversalBenchmarks.go
View file @
11a9896f
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":{">":{".":{}}}}`
)
...
...
tests/unmarshalBenchmarks.go
View file @
11a9896f
...
...
@@ -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
)
}
}
tests/util.go
0 → 100644
View file @
11a9896f
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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment