-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathbenchmark_medium_payload_test.go
More file actions
70 lines (63 loc) · 1.42 KB
/
benchmark_medium_payload_test.go
File metadata and controls
70 lines (63 loc) · 1.42 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package go_benchmark
import (
"testing"
"github.com/json-iterator/go"
"encoding/json"
"github.com/mailru/easyjson/jlexer"
"bytes"
"github.com/mailru/easyjson/jwriter"
)
/*
encoding/json
*/
func BenchmarkDecodeStdStructMedium(b *testing.B) {
b.ReportAllocs()
var data MediumPayload
for i := 0; i < b.N; i++ {
json.Unmarshal(mediumFixture, &data)
}
}
func BenchmarkEncodeStdStructMedium(b *testing.B) {
var data MediumPayload
json.Unmarshal(mediumFixture, &data)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
json.Marshal(data)
}
}
func BenchmarkDecodeJsoniterStructMedium(b *testing.B) {
b.ReportAllocs()
var data MediumPayload
for i := 0; i < b.N; i++ {
jsoniter.Unmarshal(mediumFixture, &data)
}
}
func BenchmarkEncodeJsoniterStructMedium(b *testing.B) {
var data MediumPayload
jsoniter.Unmarshal(mediumFixture, &data)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
jsoniter.Marshal(data)
}
}
func BenchmarkDecodeEasyJsonMedium(b *testing.B) {
b.ReportAllocs()
var data MediumPayload
for i := 0; i < b.N; i++ {
lexer := &jlexer.Lexer{Data: mediumFixture}
data.UnmarshalEasyJSON(lexer)
}
}
func BenchmarkEncodeEasyJsonMedium(b *testing.B) {
var data MediumPayload
lexer := &jlexer.Lexer{Data: mediumFixture}
data.UnmarshalEasyJSON(lexer)
b.ReportAllocs()
buf := &bytes.Buffer{}
for i := 0; i < b.N; i++ {
writer := &jwriter.Writer{}
data.MarshalEasyJSON(writer)
buf.Reset()
writer.DumpTo(buf)
}
}