From a1a7802fa5dd65695021578d7a7bb66352c07cd8 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 7 Sep 2018 10:06:58 -0700 Subject: [PATCH] fix benchmarks Make sure we *actually* serialize/deserialize. Addresses @warpfork's CR. --- wrap_test.go | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/wrap_test.go b/wrap_test.go index bd443be..0a513d1 100644 --- a/wrap_test.go +++ b/wrap_test.go @@ -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}, } } @@ -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) + } + } +}