From a quick Google of the classes you're instantiating, it looks like you're using the bitstring
module. This is written in pure Python, so it's not a big surprise that it's pretty slow. You might look at one or more of the following:
struct
- a module that comes with Python that will let you pack and unpack C structures into constituent valuesbytearray
- a built-in type that lets you accumulate, well, an array of bytes, and has both list-like and string-like operationsbin(x)
,int(x, 2)
- conversion of numbers to a binary representation as a string, and back - string manipulations can sometimes be a reasonably efficient way to do thisbitarray
- native (C) module for bit manipulation, looks like it has similar functionality tobitstring
but should be much faster. Available here in form suitable for compiling on Linux or here pre-compiled for Windows.numpy
- fast manipulation of arrays of various types including single bytes. Kind of the go-to module for this sort of thing, frankly. http://www.numpy.org/