Last active
November 11, 2015 10:50
-
-
Save yoki123/4d19370f908e285b52f1 to your computer and use it in GitHub Desktop.
pypy_serializing_compare
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
import time | |
import pickle | |
import cPickle | |
import marshal | |
import msgpack #(0.4.6) | |
data = ( | |
12345678, | |
1.2345678, | |
"12345678", | |
[1, 2, 3, 4, 5, 6, 7, 8], | |
{"a": 11, "b": 22} | |
) | |
num_of_test = 1000000 | |
def test(packer): | |
en = packer.dumps(data) | |
t1 = time.clock() | |
for i in xrange(num_of_test): | |
packer.dumps(data) | |
t2 = time.clock() | |
for i in xrange(num_of_test): | |
packer.loads(en) | |
t3 = time.clock() | |
print('%s dumps: %d /s' % (packer.__name__, (num_of_test / t2 - t1))) | |
print('%s loads: %d /s' % (packer.__name__, (num_of_test / t3 - t2))) | |
if __name__ == '__main__': | |
test(marshal) | |
test(cPickle) | |
test(pickle) | |
test(msgpack) |
This file contains hidden or 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
pypy -V | |
Python 2.7.10 (850edf14b2c75573720f59e95767335fb1affe55, Oct 30 2015, 08:23:58) | |
[PyPy 4.0.0 with GCC 4.8.2 20131212 (Red Hat 4.8.2-8)] | |
100w loops | |
marshal dumps: 1324779 /s | |
marshal loads: 673769 /s | |
cPickle dumps: 136664 /s | |
cPickle loads: 92651 /s | |
pickle dumps: 60691 /s | |
pickle loads: 47731 /s | |
msgpack dumps: 1146636 /s | |
msgpack loads: 497875 /s | |
--------------- | |
ProtoPy dumps: 453171 /s | |
ProtoPy loads: 188651 /s | |
use cStringIO instead StringIO | |
ProtoPy dumps: 758877 /s | |
ProtoPy loads: 271404 /s | |
python 2.7.10 | |
cProtobuf dumps: 434782 /s | |
cProtobuf loads: 212765 /s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
marshal is most fast module in python, but marshal is not recommended as a persistence module,
see marshal doc.