项目中需要将json字符串反序列化成Python字典对象,但发现原生的json库速度非常慢,就想使用第三方库取代它,发现了orjson和rapidjson两个比较流行的第三方库,测试一下
环境
- Python 3.8.6
- macOS 11.1
- orjson 3.4.6
- rapidjson 1.0
介绍
orjson
Fast, correct Python JSON library supporting dataclasses, datetimes, and numpy
号称Python下最快的json库,项目地址:https://github.com/ijl/orjson#install
源码显示底层使用了rust,难怪那么快

rapidjson
rapidjson是腾讯开源的json库,项目地址:https://github.com/Tencent/rapidjson
底层用的C++

Python中使用需要python封装库python-rapidjson,项目地址:https://github.com/python-rapidjson/python-rapidjson
安装
orjson
>>> pip3 install orjson
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting orjson
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/dc/be/96126a886573ebbb979d67f5bc4000acb7907042b8aa3494f70d118f9395/orjson-3.4.6-cp38-cp38-macosx_10_7_x86_64.whl (231 kB)
|████████████████████████████████| 231 kB 1.5 MB/s
Installing collected packages: orjson
Successfully installed orjson-3.4.6
rapidjson
>>> pip3 install python-rapidjson
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting python-rapidjson
Downloading https://pypi.tu

项目中因原生json库反序列化速度慢,测试使用第三方库orjson和rapidjson。介绍了运行环境,orjson号称Python最快json库,底层用rust;rapidjson是腾讯开源,底层用C++。还提及了安装情况,并将对dumps、loads等进行对比。
最低0.47元/天 解锁文章
392

被折叠的 条评论
为什么被折叠?



