Skip to content

Commit d52ee2f

Browse files
committed
Copy encodetestInstance to bson.D representation for benchmarks.
1 parent 506c3cd commit d52ee2f

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

bson/benchmark_test.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ import (
1919
"testing"
2020
)
2121

22+
var encodetestBsonD D
23+
24+
func init() {
25+
b, err := Marshal(encodetestInstance)
26+
if err != nil {
27+
panic(fmt.Sprintf("error marshling struct: %v", err))
28+
}
29+
30+
err = Unmarshal(b, &encodetestBsonD)
31+
if err != nil {
32+
panic(fmt.Sprintf("error unmarshaling BSON: %v", err))
33+
}
34+
}
35+
2236
type encodetest struct {
2337
Field1String string
2438
Field1Int64 int64
@@ -195,21 +209,8 @@ func BenchmarkMarshal(b *testing.B) {
195209
value: nestedInstance,
196210
},
197211
{
198-
desc: "simple D",
199-
value: D{
200-
{"field1String", "foo"},
201-
{"field1Int64", int64(1)},
202-
{"field1Float64", float64(3.0)},
203-
{"field2String", "bar"},
204-
{"field2Int64", int64(2)},
205-
{"field2Float64", float64(3.1)},
206-
{"field3String", "baz"},
207-
{"field3Int64", int64(3)},
208-
{"field3Float64", float64(3.14)},
209-
{"field4String", "qux"},
210-
{"field4Int64", int64(4)},
211-
{"field4Float64", float64(3.141)},
212-
},
212+
desc: "simple D",
213+
value: encodetestBsonD,
213214
},
214215
{
215216
desc: "deep_bson.json.gz",

0 commit comments

Comments
 (0)