Created
February 23, 2012 11:31
-
-
Save def/1892477 to your computer and use it in GitHub Desktop.
serialize
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
def load_obj(data): | |
try: | |
return cPickle.loads(zlib.decompress(data)) | |
except zlib.error: | |
return cPickle.loads(data) | |
def dump_obj(obj): | |
# In [24]: %timeit zlib.compress(cPickle.dumps(a, protocol=cPickle.HIGHEST_PROTOCOL), 1) | |
# 1000 loops, best of 3: 1.74 ms per loop | |
# In [25]: %timeit zlib.compress(cPickle.dumps(a)) | |
# 10 loops, best of 3: 34.9 ms per loop | |
pickled_data = cPickle.dumps(obj, protocol=cPickle.HIGHEST_PROTOCOL) | |
zipped_data = zlib.compress(pickled_data, 1) | |
return zipped_data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment