内容简介:推荐一个json库with -inline && -unsafe, you can get most performance generate code with -m, gojson will generate marshal/unmarshal/both for all expose structs in input dir/file.
推荐一个json库 gojson
,可以通过命令行 工具 根据输入的Struct动态生成 MarshalJSON/UnmarshalJSON
方法,性能与EasyJSON、Jsonparser、Jsoniter相比要好很多
GoJSON
GoJSON
is a fast and easy package to marshal/unmarshal struct to/from json. You can use GoJSON
tool to generate marshal/unmarshal code, in benchmark tests, GoJSON
's generate code is almost 6~7 times faster than encoding/json
.
Example
# install go get -u -v github.com/go-fish/gojson cd ${GOPATH}/src/github.com/go-fish/gojson/cmd go build -o gojson main.go # usage gojson [options] <input dir|file> -inline Use inline function in generate code (default true) -m string Mode of generate, eg: encode, decode, all (default "all") -o string Optional name of the output file to be generated. (default "gojson.generate.go") -unsafe Use decoder without copy data -version Show version information.
with -inline && -unsafe, you can get most performance generate code with -m, gojson will generate marshal/unmarshal/both for all expose structs in input dir/file.
For expose structs, gojson generate MarshalJSON/UnmarshalJSON
methods for marshal/unmarshal json. You also can use gojson.Marshal/gojson.Unmarshal
functions to marshal/unmarshal json.
Benchmark
Large Payload
Unmarshal
gojson | 114658 ns/op | 457.72 MB/s | 5873 B/op | 253 allocs/op |
---|---|---|---|---|
jsonparser | 116647 ns/op | 449.92 MB/s | 0 B/op | 0 allocs/op |
easyjson | 219673 ns/op | 238.91 MB/s | 9264 B/op | 349 allocs/op |
gojay | 92398 ns/op | 567.99 MB/s | 5985 B/op | 259 allocs/op |
jsoniter | 159877 ns/op | 328.26 MB/s | 800 B/op | 29 allocs/op |
encoding/json | 680867 ns/op | 377.08 MB/s | 6154 B/op | 258 allocs/op |
Marshal
gojson | 131 ns/op | 400511.56 MB/s | 32 B/op | 1 allocs/op |
---|---|---|---|---|
easyjson | 235 ns/op | 223039.53 MB/s | 272 B/op | 3 allocs/op |
encoding/json | 597 ns/op | 87819.16 MB/s | 120 B/op | 4 allocs/op |
Medium Payload
Unmarshal
gojson | 4056 ns/op | 510.51 MB/s | 240 B/op | 10 allocs/op |
---|---|---|---|---|
jsonparser | 9379 ns/op | 220.81 MB/s | 0 B/op | 0 allocs/op |
easyjson | 8107 ns/op | 255.43 MB/s | 288 B/op | 11 allocs/op |
gojay | 5004 ns/op | 413.84 MB/s | 2472 B/op | 10 allocs/op |
jsoniter | 10579 ns/op | 195.75 MB/s | 2576 B/op | 12 allocs/op |
encoding/json | 28030 ns/op | 73.88 MB/s | 520 B/op | 15 allocs/op |
Marshal
gojson | 105 ns/op | 19551.00 MB/s | 32 B/op | 1 allocs/op |
---|---|---|---|---|
easyjson | 193 ns/op | 10700.99 MB/s | 272 B/op | 3 allocs/op |
encoding/json | 443 ns/op | 4667.11 MB/s | 120 B/op | 4 allocs/op |
Small Payload
Unmarshal
gojson | 812 ns/op | 176.00 MB/s | 160 B/op | 5 allocs/op |
---|---|---|---|---|
jsonparser | 925 ns/op | 154.47 MB/s | 0 B/op | 0 allocs/op |
easyjson | 1209 ns/op | 118.26 MB/s | 128 B/op | 8 allocs/op |
gojay | 977 ns/op | 146.30 MB/s | 304 B/op | 6 allocs/op |
jsoniter | 1847 ns/op | 77.42 MB/s | 336 B/op | 7 allocs/op |
encoding/json | 2576 ns/op | 55.49 MB/s | 328 B/op | 7 allocs/op |
Marshal
gojson | 331 ns/op | 431.90 MB/s | 32 B/op | 1 allocs/op |
---|---|---|---|---|
easyjson | 439 ns/op | 325.35 MB/s | 272 B/op | 3 allocs/op |
encoding/json | 1398 ns/op | 102.22 MB/s | 120 B/op | 4 allocs/op |
Questions
Any questions or bugs can go though github issues.
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 打造工业级推荐系统(五):推荐系统冷启动全解析
- 京东个性化推荐系统解析
- Apache Iceberg 对推荐应用架构的优化及读写流程解析
- 分析:基于文本内容推荐和协同过滤推荐
- 《文章推荐系统》系列之推荐流程设计
- 只推荐一本 JavaScript 书,你推荐哪本?
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
数学与生活(修订版)
[日] 远山启 / 吕砚山、李诵雪、马杰、莫德举 / 人民邮电出版社 / 2014-10 / 42.00元
数学是高等智慧生物的共有思维,是对真理的探索,对矛盾的怀疑,但它绝非一门晦涩难懂的学问,非应试目的的数学是纯粹而朴实的智慧。《数学与生活》为日本数学教育改革之作,旨在还原被考试扭曲的数学,为读者呈现数学的真正容颜,消除应试教学模式带来的数学恐惧感。 本书既包含了初等数学的基础内容,又包含了微分、积分、微分方程、费马定理、欧拉公式等高等数学的内容。作者运用了多个学科的知识。结合日常生活和东西方......一起来看看 《数学与生活(修订版)》 这本书的介绍吧!