Skip to content

Instantly share code, notes, and snippets.

@koverholt
Created March 20, 2015 20:29
Show Gist options
  • Save koverholt/aef77398efc84de0b79a to your computer and use it in GitHub Desktop.
Save koverholt/aef77398efc84de0b79a to your computer and use it in GitHub Desktop.
from __future__ import division
import bloscpack
import cPickle
import numpy as np
import timeit
x = np.empty(10000000)
# cPickle without protocol keyword argument
s = timeit.Timer('cPickle.dumps(x)', 'from __main__ import cPickle, x')
time = s.timeit(1)
speed = x.nbytes / 1e6 / time
print 'Time: %0.2e s; Speed: %0.2f MB/s' % (time, speed)
# cPickle with protocol keyword argument
s = timeit.Timer('cPickle.dumps(x, protocol=2)', 'from __main__ import cPickle, x')
time = s.timeit(1)
speed = x.nbytes / 1e6 / time
print 'Time: %0.2e s; Speed: %0.2f MB/s' % (time, speed)
# Using bloscpack (serialization library with compression)
s = timeit.Timer('bloscpack.pack_ndarray_str(x)', 'from __main__ import bloscpack, x')
time = s.timeit(1)
speed = x.nbytes / 1e6 / time
print 'Time: %0.2e s; Speed: %0.2f MB/s' % (time, speed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment