Skip to content

Commit f25701a

Browse files
committed
Added benchmark
1 parent ddff4ec commit f25701a

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ default: vet test
33
test:
44
go test ./...
55

6+
bench:
7+
go test ./... -bench=. -run=NONE
8+
69
vet:
710
go vet ./...

bench_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
}

openrtb_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package openrtb
22

33
import (
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 }
1919
func sptr(s string) *string { return &s }
2020

2121
func 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
}

0 commit comments

Comments
 (0)