Skip to content

Instantly share code, notes, and snippets.

@def
Created January 27, 2012 12:20
Show Gist options
  • Save def/1688531 to your computer and use it in GitHub Desktop.
Save def/1688531 to your computer and use it in GitHub Desktop.
base64 vs binascii
marshal dumps: 0.0218579769135
marshal dumps with base64: 0.0708141326904
marshal dumps with binascii: 0.0610530376434
marshal loads: 0.0211379528046
marshal loads with base64: 0.0429949760437
marshal loads with base64: 0.0391380786896
import cPickle as pickle
import base64
import time
import marshal
import zlib
import binascii
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):
marshal.dumps(data)
print 'marshal dumps: %s' % (time.time()-t)
t = time.time()
for i in range(10000):
base64.encodestring(marshal.dumps(data))
print 'marshal dumps with base64: %s' % (time.time()-t)
t = time.time()
for i in range(10000):
binascii.b2a_qp(marshal.dumps(data))
print 'marshal dumps with binascii: %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)
d = base64.b64encode(marshal.dumps(data))
t = time.time()
for i in range(10000):
marshal.loads(base64.decodestring(d))
print 'marshal loads with base64: %s' % (time.time()-t)
d = binascii.b2a_qp(marshal.dumps(data))
t = time.time()
for i in range(10000):
marshal.loads(binascii.a2b_qp(d))
print 'marshal loads with base64: %s' % (time.time()-t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment