Skip to content

Instantly share code, notes, and snippets.

@esc
Last active December 15, 2015 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esc/5326039 to your computer and use it in GitHub Desktop.
Save esc/5326039 to your computer and use it in GitHub Desktop.
Benchmarking two techniques for compressing numpy arrays with python-blosc.
""" Benchmarking two techniques for compressing numpy arrays with python-blosc.
"""
import numpy
import numpy.random
import time
import blosc
import blosc.blosc_extension as ext
in_ = numpy.arange(3e7)
print in_
tic = (time.time())
c = blosc.pack_array(in_)
out = blosc.unpack_array(c)
assert((in_ == out).all())
toc = (time.time())
print toc-tic
tic = (time.time())
c = ext.compress_ptr(in_.__array_interface__['data'][0],
in_.size*in_.dtype.itemsize,
in_.dtype.itemsize, 9, True)
out = numpy.empty(in_.size, dtype=in_.dtype)
d = ext.decompress_ptr(c, out.__array_interface__['data'][0])
assert((in_ == out).all())
assert(d == in_.size*in_.dtype.itemsize)
toc = (time.time())
print toc-tic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment