forked from rtbpanda/openrtb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench_test.go
42 lines (36 loc) · 804 Bytes
/
bench_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package openrtb
import (
"encoding/json"
"io/ioutil"
"path/filepath"
"testing"
)
func BenchmarkBidRequest_Unmarshal(b *testing.B) {
data, err := ioutil.ReadFile(filepath.Join("testdata", "breq.video.json"))
if err != nil {
b.Fatal(err.Error())
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
var req *BidRequest
if err := json.Unmarshal(data, &req); err != nil {
b.Fatal(err.Error())
}
}
}
func BenchmarkBidRequest_Marshal(b *testing.B) {
data, err := ioutil.ReadFile(filepath.Join("testdata", "breq.video.json"))
if err != nil {
b.Fatal(err.Error())
}
var req *BidRequest
if err := json.Unmarshal(data, &req); err != nil {
b.Fatal(err.Error())
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
if _, err := json.Marshal(req); err != nil {
b.Fatal(err.Error())
}
}
}