Created
December 1, 2011 22:04
-
-
Save bnewbold/1420229 to your computer and use it in GitHub Desktop.
Recursive Python Serialization Benchmarks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import cPickle as pickle | |
import simplejson | |
import json | |
import cjson | |
a = { | |
'foo': 'bar', | |
'food': range(10), | |
'good': ['a', 2.45, True], | |
'dood': None, | |
'wheres your car': u'du\u03A3de?', | |
} | |
b = { | |
'foo': [a, a, a], | |
'food': 'barf', | |
'good': 3.1415, | |
'dood': None, | |
'wheres your car': u'du\u03A3de?', | |
} | |
d = { | |
'foo': 'bar', | |
'food': b, | |
'good': [a, a, b], | |
'dood': 'wheres your car?', | |
'wheres your car': 5.68, | |
} | |
print 'Starting json...' | |
start = time.time() | |
for i in xrange(100000): | |
json.dumps(d) | |
print 'done:', time.time() - start | |
print 'Starting simplejson...' | |
start = time.time() | |
for i in xrange(100000): | |
simplejson.dumps(d) | |
print 'done:', time.time() - start | |
print 'Starting cjson...' | |
start = time.time() | |
for i in xrange(100000): | |
cjson.encode(d) | |
print 'done:', time.time() - start | |
print 'Starting pickle...' | |
start = time.time() | |
for i in xrange(100000): | |
pickle.dumps(d) | |
print 'done:', time.time() - start | |
""" | |
bnewbold@trurl$ python2.7 bench_recurse.py | |
Starting json... | |
done: 3.32014203072 | |
Starting simplejson... | |
done: 3.58444595337 | |
Starting cjson... | |
done: 4.02123212814 | |
Starting pickle... | |
done: 1.48276615143 | |
bnewbold@trurl$ python2.6 bench_recurse.py | |
Starting json... | |
done: 46.5570452213 | |
Starting simplejson... | |
done: 4.57484912872 | |
Starting cjson... | |
done: 5.01646113396 | |
Starting pickle... | |
done: 1.57670092583 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment