Ultrajson -- Python's fast JSON Decoder

Source: Internet
Author: User
Tags benchmark

Lai Yonghao (http://laiyonghao.com)

Note: Not sentence-by-Sentence Translation, if you are confused, Parameter Details of the original (http://pushingtheweb.com/2011/03/ultra-fast-json-encoding-decoding-python ).

In ESN, we use JSON in large quantities. The Python 2.6 comes with a slow speed, so we will use simplejson later. Today, JavaScript and JSON are more widely used, so I think it may be a field worthy of my use of C for optimization, and it can be noted that I am not old.

Ultrajson

I spent a weekend studying JSON encoding and called the result ultrajson. From the preliminary benchmark test I have conducted, he is the fastest among all the JSON codecs I can find (if not, I can optimize it faster !).

Python binding

In fact, ultrajson is not only used in a specific language, but for convenience of use by my colleagues, I implemented its Python binding, which is called the ujson module.
Update: ultrajson can be found in pypi now. The package name is ujson. you can install it easily with easy_install or Pip, you know.

Current Benchmark Test

64-bit Linux Benchmark Test

Python 2.6.6 (r266: 84292, Sep 15 2010, 16:22:56)
OS Version: Ubuntu 10.10
System type: x64-based PC
Processor: Intel (r) core (TM) i5-2300 CPU @ 2.80 GHz
Total physical memory: 4096 MB

Array with 256 UTF-8 strings:
Ujson encode: 2874.54652 CILS/sec
Simplejson encode: 1539.47999 CILS/sec
Cjson encode: 132.33571 CILS/sec

Ujson Decode: 2072.09417 CILS/sec
Cjson Decode: 991.20903 CILS/sec
Simplejson Decode: 310.75309 CILS/sec

Medium complex object:
Ujson encode: 19001.01929 CILS/sec
Simplejson encode: 3512.29205 CILS/sec
Cjson encode: 3063.69959 CILS/sec

Ujson Decode: 12791.80993 CILS/sec
Cjson Decode: 8288.32916 CILS/sec
Simplejson Decode: 6640.22169 CILS/sec

Array with 256 strings:
Ujson encode: 40161.78453 CILS/sec
Simplejson encode: 19301.40779 CILS/sec
Cjson encode: 12337.13166 CILS/sec

Ujson Decode: 36944.81317 CILS/sec
Cjson Decode: 30187.40167 CILS/sec
Simplejson Decode: 25105.56562 CILS/sec

Array with 256 doubles:
Ujson encode: 6054.71950 CILS/sec
Simplejson encode: 2912.44353 CILS/sec
Cjson encode: 3539.51228 CILS/sec

Ujson Decode: 27794.29735 CILS/sec
Cjson Decode: 14892.38775 CILS/sec
Simplejson Decode: 14879.00070 CILS/sec

Array with 256 true values:
Ujson encode: 168086.95325 CILS/sec
Simplejson encode: 49348.93309 CILS/sec
Cjson encode: 67392.90623 CILS/sec

Ujson Decode: 139359.25968 CILS/sec
Cjson Decode: 82552.26652 CILS/sec
Simplejson Decode: 114998.51396 CILS/sec

Array with 256 dict {string, int} pairs:
Ujson encode: 24125.68837 CILS/sec
Simplejson encode: 5751.74871 CILS/sec
Cjson encode: 4735.65147 CILS/sec

Ujson Decode: 17176.70493 CILS/sec
Cjson Decode: 13420.93963 CILS/sec
Simplejson Decode: 9854.27352 CILS/sec

Dict with 256 arrays with 256 dict {string, int} pairs:
Ujson encode: 86.52449 CILS/sec
Simplejson encode: 17.46117 CILS/sec
Cjson encode: 18.31323 CILS/sec

Ujson Decode: 49.54660 CILS/sec
Cjson Decode: 38.34094 CILS/sec
Simplejson Decode: 28.18035 CILS/sec

More on GitHub

I'm looking forward to seeing someone using this project. What's better is contribution.CodeSo come to my GitHub repository (https://github.com/jskorpan/ultrajson.
It would be cool to bind it to more languages!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.