Created
April 12, 2013 16:05
-
-
Save schlamar/5373110 to your computer and use it in GitHub Desktop.
Another serialization benchmark, OSX Python 2.7.3
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 cPickle | |
import json | |
import ujson | |
import msgpack | |
d = { | |
'words': """ | |
Lorem ipsum dolor sit amet, consectetur adipiscing | |
elit. Mauris adipiscing adipiscing placerat. | |
Vestibulum augue augue, | |
pellentesque quis sollicitudin id, adipiscing. | |
""", | |
'list': range(50), | |
'dict': dict((str(i),'a') for i in xrange(50)), | |
'int': 100, | |
'float': 100.123456 | |
} | |
print "*Encoding*" | |
print "cPickle.dumps (binary)" | |
%timeit _ = cPickle.dumps(d, 2) | |
pickle_src = cPickle.dumps(d, 2) | |
print "json.dumps" | |
%timeit _ = json.dumps(d) | |
json_src = json.dumps(d) | |
print "ujson.dumps" | |
%timeit _ = ujson.dumps(d) | |
ujson_src = ujson.dumps(d) | |
print "msgpack.dumps" | |
%timeit _ = msgpack.dumps(d) | |
msgpack_src = msgpack.dumps(d) | |
print "*Decoding*" | |
print "cPickle.loads (binary)" | |
%timeit _ = cPickle.loads(pickle_src) | |
print "json.loads" | |
%timeit _ = json.loads(json_src) | |
print "ujson.loads" | |
%timeit _ = ujson.loads(ujson_src) | |
print "msgpack.loads" | |
%timeit _ = msgpack.loads(msgpack_src) | |
''' | |
*Encoding* | |
cPickle.dumps (binary) | |
100000 loops, best of 3: 10.2 us per loop | |
json.dumps | |
10000 loops, best of 3: 29.6 us per loop | |
ujson.dumps | |
100000 loops, best of 3: 7.65 us per loop | |
msgpack.dumps | |
100000 loops, best of 3: 7.95 us per loop | |
*Decoding* | |
cPickle.loads (binary) | |
100000 loops, best of 3: 12.2 us per loop | |
json.loads | |
10000 loops, best of 3: 57.7 us per loop | |
ujson.loads | |
100000 loops, best of 3: 12.4 us per loop | |
msgpack.loads | |
100000 loops, best of 3: 6.22 us per loop | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment