Skip to content

Commit 61a5420

Browse files
jacksontjalecthomas
authored andcommitted
Add jsoniter to benchmarks (alecthomas#63)
1 parent 64e770c commit 61a5420

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This is a test suite for benchmarking various Go serialization methods.
88

99
- [encoding/gob](http://golang.org/pkg/encoding/gob/)
1010
- [encoding/json](http://golang.org/pkg/encoding/json/)
11+
- [github.com/json-iterator/go](https://github.com/json-iterator/go)
1112
- [github.com/alecthomas/binary](https://github.com/alecthomas/binary)
1213
- [github.com/davecgh/go-xdr/xdr](https://github.com/davecgh/go-xdr)
1314
- [github.com/Sereal/Sereal/Go/sereal](https://github.com/Sereal/Sereal)

serialization_benchmarks_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/gogo/protobuf/proto"
2121
flatbuffers "github.com/google/flatbuffers/go"
2222
"github.com/hprose/hprose-go"
23+
jsoniter "github.com/json-iterator/go"
2324
"github.com/ikkerens/ikeapack"
2425
"github.com/tinylib/msgp/msgp"
2526
"github.com/ugorji/go/codec"
@@ -209,6 +210,31 @@ func BenchmarkJsonUnmarshal(b *testing.B) {
209210
benchUnmarshal(b, JsonSerializer{})
210211
}
211212

213+
// github.com/json-iterator/go
214+
215+
type JsonIterSerializer struct{}
216+
217+
func (j JsonIterSerializer) Marshal(o interface{}) []byte {
218+
d, _ := jsoniter.Marshal(o)
219+
return d
220+
}
221+
222+
func (j JsonIterSerializer) Unmarshal(d []byte, o interface{}) error {
223+
return jsoniter.Unmarshal(d, o)
224+
}
225+
226+
func (j JsonIterSerializer) String() string {
227+
return "jsoniter"
228+
}
229+
230+
func BenchmarkJsonIterMarshal(b *testing.B) {
231+
benchMarshal(b, JsonIterSerializer{})
232+
}
233+
234+
func BenchmarkJsonIterUnmarshal(b *testing.B) {
235+
benchUnmarshal(b, JsonIterSerializer{})
236+
}
237+
212238
// github.com/mailru/easyjson
213239

214240
type EasyJSONSerializer struct{}

0 commit comments

Comments
 (0)