File tree Expand file tree Collapse file tree 3 files changed +30
-3
lines changed
Expand file tree Collapse file tree 3 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -3,5 +3,8 @@ default: vet test
33test :
44 go test ./...
55
6+ bench :
7+ go test ./... -bench=. -run=NONE
8+
69vet :
710 go vet ./...
Original file line number Diff line number Diff line change 1+ package openrtb
2+
3+ import (
4+ "encoding/json"
5+ "io/ioutil"
6+ "path/filepath"
7+ "testing"
8+ )
9+
10+ func BenchmarkBidRequest_Unmarshal (b * testing.B ) {
11+ data , err := ioutil .ReadFile (filepath .Join ("testdata" , "breq.video.json" ))
12+ if err != nil {
13+ b .Fatal (err .Error ())
14+ }
15+
16+ b .ResetTimer ()
17+ for i := 0 ; i < b .N ; i ++ {
18+ var req * BidRequest
19+ if err := json .Unmarshal (data , & req ); err != nil {
20+ b .Fatal (err .Error ())
21+ }
22+ }
23+ }
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ package openrtb
22
33import (
44 "encoding/json"
5- "io/ioutil "
5+ "os "
66 "path/filepath"
77 "testing"
88
@@ -19,9 +19,10 @@ func iptr(n int) *int { return &n }
1919func sptr (s string ) * string { return & s }
2020
2121func fixture (fname string , v interface {}) error {
22- data , err := ioutil . ReadFile (filepath .Join ("testdata" , fname + ".json" ))
22+ f , err := os . Open (filepath .Join ("testdata" , fname + ".json" ))
2323 if err != nil {
2424 return err
2525 }
26- return json .Unmarshal (data , v )
26+ defer f .Close ()
27+ return json .NewDecoder (f ).Decode (v )
2728}
You can’t perform that action at this time.
0 commit comments