Lolrus.org

This is a header that goes on every page.

simplejson vs. python-cjson

January 25, 2008 at 10:28 AM | categories: Uncategorized | Comment

I needed a package that decodes JSON into dictionaries/lists etc.  I've used simplejson in the past and it's worked fairly well.  I came across another package today that claims to be at least a hundred times faster than the other JSON implementations for python called cjson.  I was a bit skeptical because simplejson has C extensions too.

I decided to run some quick benchmarks.  The code I ran can be found here.

benchmark data: processor: Intel(R) Core(TM)2 CPU 6600 @ 2.40GHz x86_64 Linux. simplejson 1.7.3 (I assume the c extensions are enabled because I used emerge to get it) python-cjson 1.0.5 Python 2.5.1

simplejson results: % time ./simplejsonbench.py ./simplejsonbench.py 38.97s user 0.00s system 99% cpu 38.968 total % time ./simplejsonbench.py ./simplejsonbench.py 39.17s user 0.01s system 99% cpu 39.187 total

cjson results: % time ./cjsonbenchmark.py ./cjsonbenchmark.py 0.77s user 0.01s system 99% cpu 0.784 total % time ./cjsonbenchmark.py ./cjsonbenchmark.py 0.77s user 0.03s system 100% cpu 0.794 total

simplejson average: 39.07s cjson average: 0.77s

verdict: cjson 50.74x faster in this benchmark

I'd run more, but I don't really think I have to. Simplejson actually seems to have a more robust interface than cjson, and is more portable because it doesn't require a C compiler.

The cjson website has some other numbers that measure actual measured throughput of cjson vs. simplejson. The versions of simplejson is older, and it states there's no C extensions compiled in.

blog comments powered by Disqus