This is a creation in Article, where the information may have evolved or changed.
Full text link:https://github.com/json-iterator/go-benchmark
The aim is not to sell json-iterator. Instead, it proves that json-iterator is no slower than the rest of the library, so that you can put the spit point in other ways: For example, the feature is not complete, the API is not friendly. The re-inventing of the JSON parser is because it is often necessary to deal with the strange format of JSON, and do not want to turn the data two times. There is no API in the market to meet my needs, I will write a special article on the API to demonstrate the uniqueness of json-iterator. (Https://github.com/json-itera ... )
Jsonparser:https://github.com/buger/jsonparser
Jsoniter Pull-api:https://github.com/json-iterator/go
Jsoniter Reflect-api:https://github.com/json-iterator/go/blob/master/jsoniter_reflect.go
Encoding/json:golang Standard Lib
Easy JSON:https://github.com/mailru/easyjson
Test equipment
cpu:i7-6700k @ 4.0G
Level 1 Cache size:4 x KB 8-way set associative instruction caches
Level 2 cache Size:4 x KB 4-way set associative caches
Level 3 Cache Size:8 MB 16-way set associative shared cache
Go:1.8beta1
Small payload
Https://github.com/json-itera ...
Jsonparser |
Jsoniter Pull-api |
Jsoniter Reflect-api |
Encoding/json |
Easyjson |
599 NS/OP |
515 Ns/op |
684 ns/op |
2453 Ns/op |
687 Ns/op |
B/op |
B/op |
B/op |
864 b/op |
B/op |
2 allocs/op |
2 allocs/op |
4 allocs/op |
Allocs/op |
2 allocs/op |
Encoding/json has a good performance on i7-6700k, but it's much slower to cache on smaller CPUs.
Medium payload
Jsonparser |
Jsoniter Pull-api |
Jsoniter Reflect-api |
Encoding/json |
Easyjson |
5238 ns/op |
4111 ns/op |
4708 ns/op |
24939 ns/op |
7361 ns/op |
104 B/op |
104 B/op |
368 b/op |
808 B/op |
248 b/op |
4 allocs/op |
4 allocs/op |
Allocs/op |
Allocs/op |
8 Allocs/op |
Https://github.com/json-itera ...
Json-iterator's reflection API is also fairly fast.
Large payload
Https://github.com/json-itera ...
Jsonparser |
Jsoniter Pull-api |
Encoding/json |
38334 ns/op |
38463 ns/op |
290778 ns/op |
0 b/op |
0 b/op |
2128 B/op |
0 allocs/op |
0 allocs/op |
Allocs/op |
Jsonparser is a little faster when most fields are not used.
Large file
Test file Used:https://github.com/json-itera ...
Jsonparser |
Jsoniter Pull-api |
Encoding/json |
42698634 ns/op |
37760014 ns/op |
235354502 ns/op |
67107104 b/op |
4248 B/op |
71467896 b/op |
Allocs/op |
5 allocs/op |
272477 allocs/op |
Jsonparser and other a whole bunch of JSON parsers are "]byte" as input, just for running points. On this point Jackson's author also has a spit groove (https://www.infoq.com/news/20 ... )。 and jsoniter can support IO. Reader as input, very friendly for large file handling.