3 ms·
About JSON: Python 2.6 added a "json" module to the standard library that was forked from simplejson, but in that time, simplejson has improved; the interface i
by pjscott 15y ago
About JSON: Python 2.6 added a "json" module to the standard library that was forked from simplejson, but in that time, simplejson has improved; the interface is exactly the same as the built-in json module, but simplejson tends to be quite a bit faster.
On my informal benchmark of JSON parsing speed, simplejson was 27x faster than json.
The idiom I've been using is:
try:
import simplejson as json
except ImportError:
import json
- d0mine 15y agoDocumentation for simplejson mentions that it should be faster. Though it contains reference to Python 2.5, 2.6 so It is unclear whether the claim is outdated: It is the externally maintained version of the json library contained in Python 2.6, but maintains compatibility with Python 2.5 and (currently) has significant performance advantages, even without using the optional C extension for speedups. </quote> http://simplejson.readthedocs.org/en/latest/index.html http://simplejson.readthedocs.org/en/latest/index.html I see there are performance patches to stdlib's json since 2.6: http://hg.python.org/cpython/search/?rev=_json.c&revcount=80 http://hg.python.org/cpython/search/?rev=_json.c&revcoun... An order of magnitude difference might be an issue with your python installation. On my machine version from 2.6 (1.9) is 15 times slower than from 2.7 (2.0.9). Though simplejson (2.2.1) is still faster on both 40 and 2 times correspondingly for .loads() timeline.js from the example as measured by: % timeit json.loads(timeline_text) it seems that C speedups available on both versions: python -v -c'import json' 2>&1 | grep _json.so python -c'import json.decoder as d; print d.scanstring' Is your python version old? Otherwise it is worth to open issues at http://bugs.python.org http://bugs.python.org to merge speed improvements and at https://github.com/simplejson/simplejson/issues https://github.com/simplejson/simplejson/issues to mention in the docs and on http://pypi.python.org/pypi/simplejson http://pypi.python.org/pypi/simplejson more clearly that Python 2.7+ stdlib's version is also slower.
- pjscott 15y agoI'm stuck on 2.6 for now, so that's probably the main issue.