Skip to content

Commit

Permalink
fix benchmarks
Browse files Browse the repository at this point in the history
Make sure we *actually* serialize/deserialize. Addresses @warpfork's CR.
  • Loading branch information
Stebalien committed Sep 12, 2018
1 parent 5896ec2 commit a1a7802
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@ import (
mh "github.com/multiformats/go-multihash"
)

type myStruct struct {
items map[string]myStruct
foo string
bar []byte
baz []int
type MyStruct struct {
Items map[string]MyStruct
Foo string
Bar []byte
Baz []int
}

func init() {
RegisterCborType(myStruct{})
RegisterCborType(MyStruct{})
}

func testStruct() myStruct {
return myStruct{
items: map[string]myStruct{
"foo": {
foo: "foo",
bar: []byte("bar"),
baz: []int{1, 2, 3, 4},
func testStruct() MyStruct {
return MyStruct{
Items: map[string]MyStruct{
"Foo": {
Foo: "Foo",
Bar: []byte("Bar"),
Baz: []int{1, 2, 3, 4},
},
"bar": {
bar: []byte("bar"),
baz: []int{1, 2, 3, 4},
"Bar": {
Bar: []byte("Bar"),
Baz: []int{1, 2, 3, 4},
},
},
baz: []int{5, 1, 2},
Baz: []int{5, 1, 2},
}
}

Expand Down Expand Up @@ -102,3 +102,13 @@ func BenchmarkDecodeBlockParallel(b *testing.B) {
}
wg.Wait()
}

func BenchmarkDumpObject(b *testing.B) {
obj := testStruct()
for i := 0; i < b.N; i++ {
bytes, err := DumpObject(obj)
if err != nil {
b.Fatal(err, bytes)
}
}
}

0 comments on commit a1a7802

Please sign in to comment.