Created
April 4, 2012 22:12
-
-
Save juandebravo/2306072 to your computer and use it in GitHub Desktop.
cpython_json_cjson_pickle
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 json | |
import cjson | |
import ujson | |
d = { | |
'foo': 'bar', | |
'food': 'barf', | |
'good': 'bars', | |
'dood': 'wheres your car?', | |
'wheres your car': 'dude?', | |
} | |
print 'Starting json...' | |
start = time.time() | |
for i in xrange(1000000): | |
json.dumps(d) | |
print 'done:', time.time() - start | |
print 'Starting cjson...' | |
start = time.time() | |
for i in xrange(1000000): | |
cjson.encode(d) | |
print 'done:', time.time() - start | |
print 'Starting ujson...' | |
start = time.time() | |
for i in xrange(1000000): | |
ujson.encode(d) | |
print 'done:', time.time() - start | |
print 'Starting pickle...' | |
start = time.time() | |
for i in xrange(1000000): | |
pickle.dumps(d) | |
print 'done:', time.time() - start | |
# cpython 2.7 | |
#Starting json... | |
#done: 17.138479948 | |
Starting cjson... | |
#done: 4.70037078857 | |
#Starting ujson... | |
#done: 1.57113099098 | |
#Starting pickle... | |
#done: 13.5882430077 | |
# | |
# cpython 2.6.6 | |
#Starting json... | |
#done: 24.083124876 | |
#Starting cjson... | |
#done: 2.36736512184 | |
#Starting pickle... | |
#done: 7.88932514191 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your results are not really reliable, see https://gist.github.com/3134391.