Created
January 27, 2012 11:38
-
-
Save def/1688407 to your computer and use it in GitHub Desktop.
cPickle vs cPickle+HIGHEST_PROTOCOL vs marshal
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
cPickle default dumps: 0.107237100601 | |
cPickle HIGHEST_PROTOCOL dumps: 0.0678668022156 | |
marshal dumps: 0.0203359127045 | |
cPickle default loads: 0.0411729812622 | |
cPickle HIGHEST_PROTOCOL loads: 0.0352649688721 | |
marshal loads: 0.0221829414368 |
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 as pickle | |
import base64 | |
import time | |
import marshal | |
data = ((u'instance', u's3750'), (u'interface', u'Gi1/0/22'), (u'name', u'ifHighSpeed'), (u'plugin', u'switch'), (u'source_hostname', u'switch3750')) | |
t = time.time() | |
for i in range(10000): | |
pickle.dumps(data) | |
print 'cPickle default dumps: %s' % (time.time()-t) | |
t = time.time() | |
for i in range(10000): | |
pickle.dumps(data, protocol=pickle.HIGHEST_PROTOCOL) | |
print 'cPickle HIGHEST_PROTOCOL dumps: %s' % (time.time()-t) | |
t = time.time() | |
for i in range(10000): | |
marshal.dumps(data) | |
print 'marshal dumps: %s' % (time.time()-t) | |
d = pickle.dumps(data) | |
t = time.time() | |
for i in range(10000): | |
pickle.loads(d) | |
print 'cPickle default loads: %s' % (time.time()-t) | |
d = pickle.dumps(data, protocol=pickle.HIGHEST_PROTOCOL) | |
t = time.time() | |
for i in range(10000): | |
pickle.loads(d) | |
print 'cPickle HIGHEST_PROTOCOL loads: %s' % (time.time()-t) | |
d = marshal.dumps(data) | |
t = time.time() | |
for i in range(10000): | |
marshal.loads(d) | |
print 'marshal loads: %s' % (time.time()-t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment