zeromq/pyzmq — pull request #188 by aelse (2012-03-09 04:48:41+00:00)
Title: Prefer ujson to other json libraries

Hi,

I am submitting my suggestion that pyzmq should prefer ultrajson to other json libraries, where it is available. I ran a few independent benchmarks of my own before i went to ultrajson's own benchmarks (which are more comprehensive). In all cases ujson was faster than the libraries that pyzmq will currently use.

As it's a small and self-explanatory patch i'm merely submitting a pull request.

I've included the output of the ultrajson benchmarks as run on my laptop. The performance difference is quite substantial.

else@else-laptop:~/code/ultrajson/tests$ python !$
python benchmark.py
Ready? Configure affinity and priority, starting in 20...
Array with 256 utf-8 strings:
ujson encode : 5292.42036 calls/sec
simplejson encode : 1065.99516 calls/sec
cjson encode : 1253.94846 calls/sec
yajl encode : 4512.93043 calls/sec
jsonlib2 encode : 364.38984 calls/sec
ujson decode : 1122.60537 calls/sec
cjson decode : 592.38340 calls/sec
simplejson decode : 316.19584 calls/sec
yajl decode : 501.33857 calls/sec
jsonlib2 decode : 158.77379 calls/sec
Medium complex object:
ujson encode : 18347.35312 calls/sec
simplejson encode : 3766.12970 calls/sec
cjson encode : 3501.12589 calls/sec
yajl encode : 4362.23704 calls/sec
jsonlib2 encode : 3360.34393 calls/sec
ujson decode : 8594.06106 calls/sec
cjson decode : 6392.18533 calls/sec
simplejson decode : 6201.59000 calls/sec
yajl decode : 4496.75869 calls/sec
jsonlib2 decode : 4506.14452 calls/sec
Array with 256 strings:
ujson encode : 42359.09099 calls/sec
simplejson encode : 20649.55218 calls/sec
cjson encode : 11653.85826 calls/sec
yajl encode : 19630.01462 calls/sec
jsonlib2 encode : 11174.07164 calls/sec
ujson decode : 20438.70344 calls/sec
cjson decode : 20665.72920 calls/sec
simplejson decode : 26664.73403 calls/sec
yajl decode : 12083.48002 calls/sec
jsonlib2 decode : 15093.42926 calls/sec
Array with 256 doubles:
ujson encode : 5200.14069 calls/sec
simplejson encode : 3080.39679 calls/sec
cjson encode : 8453.19378 calls/sec
yajl encode : 5292.46444 calls/sec
jsonlib2 encode : 2981.12800 calls/sec
ujson decode : 22081.14152 calls/sec
cjson decode : 9074.45926 calls/sec
simplejson decode : 9553.83586 calls/sec
yajl decode : 8893.22186 calls/sec
jsonlib2 decode : 5339.18216 calls/sec
Array with 256 True values:
ujson encode : 147155.75627 calls/sec
simplejson encode : 48195.23423 calls/sec
cjson encode : 59580.12833 calls/sec
yajl encode : 84058.60187 calls/sec
jsonlib2 encode : 52465.46024 calls/sec
ujson decode : 138562.05868 calls/sec
cjson decode : 62552.77974 calls/sec
simplejson decode : 99628.16731 calls/sec
yajl decode : 58459.02367 calls/sec
jsonlib2 decode : 59544.07930 calls/sec
Array with 256 dict{string, int} pairs:
ujson encode : 18528.05821 calls/sec
simplejson encode : 5221.15737 calls/sec
cjson encode : 4747.79211 calls/sec
yajl encode : 9772.05776 calls/sec
jsonlib2 encode : 5691.15677 calls/sec
ujson decode : 13131.46037 calls/sec
cjson decode : 9782.04004 calls/sec
simplejson decode : 9085.80547 calls/sec
yajl decode : 6828.52050 calls/sec
jsonlib2 decode : 6978.71961 calls/sec
Dict with 256 arrays with 256 dict{string, int} pairs:
ujson encode : 58.81370 calls/sec
simplejson encode : 12.30862 calls/sec
cjson encode : 17.08015 calls/sec
yajl encode : 35.61728 calls/sec
jsonlib2 encode : 17.79258 calls/sec
ujson decode : 30.10846 calls/sec
cjson decode : 20.96150 calls/sec
simplejson decode : 15.89374 calls/sec
yajl decode : 16.07819 calls/sec
jsonlib2 decode : 21.05826 calls/sec