V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
? http://golang.org/
? Go Playground
Go Projects
? Revel Web Framework
taowen
V2EX  ?  Go 编程语言

golang json 解析器性能评测

  •  
  •   taowen · 2016-12-07 09:47:57 +08:00 · 1384 次点击
    这是一个创建于 2698 天前的主题,其中的信息可能已经有所发展或是发生改变。

    腾讯云最新优惠活动来了:云产品限时1折,云服务器低至88元/年 ,点击这里立即抢购:9i0i.cn/qcloud,更有2860元代金券免费领取,付款直接抵现金用,点击这里立即领取:9i0i.cn/qcloudquan

    (福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun

    全文链接: https://github.com/json-iterator/go-benchmark

    目的不是推销 json-iterator 。而是证明 json-iterator 不比其他的库更慢,从而使得大家可以把吐槽点放到其他方面:比如特性是不是齐全, api 是不是友好。重新发明 json 解析器是因为经常需要处理奇怪格式的 json ,而又不想把数据转两遍。市面上没有 api 满足我的需求的,后面我会专门写一篇 api 介绍的文章来演示 json-iterator 的独特性。( https://github.com/json-iterator/go/blob/master/README.md

    测试设备

    • CPU: i7-6700K @ 4.0G
    • Level 1 cache size: 4 x 32 KB 8-way set associative instruction caches
    • Level 2 cache size: 4 x 256 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-iterator/go-benchmark/blob/master/src/github.com/json-iterator/go-benchmark/benchmark_small_payload_test.go

    encoding/json 在 i7-6700K 上性能还不错,但是在缓存小一些的 cpu 上性能要比这慢更多。

    small

    medium payload

    https://github.com/json-iterator/go-benchmark/blob/master/src/github.com/json-iterator/go-benchmark/benchmark_medium_payload_test.go

    json-iterator 的反射 api 也是相当快的。

    medium

    large payload

    https://github.com/json-iterator/go-benchmark/blob/master/src/github.com/json-iterator/go-benchmark/benchmark_large_payload_test.go

    jsonparser 在大部分字段不使用的时候,要快那么一丁点。

    large

    large file

    test file used: https://github.com/json-iterator/test-data/blob/master/large-file.json

    jsonparser 等其他一大票 json 解析器都是以 []byte 作为输入的,简直是为跑分而生。关于这一点 jackson 的作者也有吐槽( https://www.infoq.com/news/2014/05/jackson-founder-responds )。而 jsoniter 可以支持 io.Reader 作为输入,对于大文件处理非常友好。

    large-file

    1 条回复  ?  2016-12-07 17:31:58 +08:00
    ijustdo
        1
    ijustdo  
       2016-12-07 17:31:58 +08:00
    好不容易看到个写 go 的 顶一下呢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   886 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 21:59 · PVG 05:59 · LAX 14:59 · JFK 17:59
    Developed with CodeLauncher
    ? Do have faith in what you're doing.


    http://www.vxiaotou.com