Skip to main content

Faster C implementation of bitstruct

Project description

License Build Status

About

cbitstruct is a C implementation of the bitstruct library. Credits to Erik Moqvist for the original bitstruct library available on Github and pip.

The goal is to provide the same API an idealy to be able to interchange import bitstruct and import cbitstruct as bitstruct.

Obvious increased performance comes with limitations described below.

Installation

pip3 install cbitstruct

Documentation

Please refer to the bitstruct documentation as the aim of this library is to provide the same API with increased performance.

If you are not used to bitstruct, you should seriously consider using it first, before migrating to this library if you require higher performance.

Limitations

Limitation Will it be lifted ?
All types except padding are limited to 64 bits Maybe for 'raw' and 'text' types
May not work on big-endian architectures Maybe
Exceptions differ from bitstruct Probably not
CPython only Probably not
Error messages are unclear Will never be as clear as bitstruct
Python >= 3.5 No

Some limitations are there because I did not get the time or motivation to lift them up. Some other are deeply rooted into this library and may never be lifted.

Performance

Comparing to bitstruct

The script available in tests/test_perf.py measures performance comparing to the bitstruct library.

Here are the result "on my machine" (Ubuntu in Virtualbox on a laptop):

byteswap list of int      | x  8.779 (   8.638us ->   0.984us)
byteswap str              | x 17.466 (   9.158us ->   0.524us)
calcsize                  | x139.330 (  61.060us ->   0.438us)
compiled pack             | x 47.389 (  35.968us ->   0.759us)
compiled pack_dict        | x 27.184 (  34.588us ->   1.272us)
compiled pack_into        | x 32.037 (  38.650us ->   1.206us)
compiled pack_into_dict   | x 27.343 (  37.718us ->   1.379us)
compiled unpack           | x 33.928 (  31.278us ->   0.922us)
compiled unpack_dict      | x 21.627 (  31.597us ->   1.461us)
compiled unpack_from      | x 30.622 (  29.977us ->   0.979us)
compiled unpack_from_dict | x 20.479 (  30.936us ->   1.511us)
pack                      | x 77.003 ( 103.030us ->   1.338us)
pack_dict                 | x 53.254 ( 103.255us ->   1.939us)
pack_into                 | x 82.829 ( 119.373us ->   1.441us)
pack_into_dict            | x 52.173 ( 108.135us ->   2.073us)
unpack                    | x 78.459 (  91.896us ->   1.171us)
unpack_dict               | x 40.287 (  89.300us ->   2.217us)
unpack_from               | x 77.027 (  91.202us ->   1.184us)
unpack_from_dict          | x 39.467 (  88.043us ->   2.231us)

Disclaimer: these results may and will vary largely depending on the number of elements and types you pack/unpack. This script is provided as-is, and I will gladly accept an improved script providing more reliable results.

The dict API

The dict API is marginally slower than the traditional one. As the packing/unpacking performance is quite high, the overhead of performing dictionary lookups and hashing significantly increas pack and unpacking duration.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cbitstruct-1.1.0.tar.gz (29.3 kB view details)

Uploaded Source

Built Distributions

cbitstruct-1.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (72.5 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

cbitstruct-1.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (71.6 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

cbitstruct-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (69.6 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

cbitstruct-1.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (69.5 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

cbitstruct-1.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (69.5 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

cbitstruct-1.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (68.2 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

cbitstruct-1.1.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (68.2 kB view details)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

File details

Details for the file cbitstruct-1.1.0.tar.gz.

File metadata

  • Download URL: cbitstruct-1.1.0.tar.gz
  • Upload date:
  • Size: 29.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for cbitstruct-1.1.0.tar.gz
Algorithm Hash digest
SHA256 43b8d11b4c8042eb2273018698653b49573f97d0f9816e825ff2e89e2e835e39
MD5 310864f07251cd415dd95b380a015d78
BLAKE2b-256 a1d5b3bceb3515e71df2d7a3493e3a4f2e050ec5eac30ac957c8e2f4c2e9216f

See more details on using hashes here.

File details

Details for the file cbitstruct-1.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cbitstruct-1.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 83712fb7758e8f99823ae2be629d78fa92e3879ba4d329d22651ef76c562fb61
MD5 cfcd131732f4a2ba100c212d95fa7226
BLAKE2b-256 b776114378e8ea70ccd2681bd5a489b5729b400de586d8553f2708e60749977a

See more details on using hashes here.

File details

Details for the file cbitstruct-1.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cbitstruct-1.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c4197911d32659e89b7699428d19e6eb7ba37eb585227eb691587cd87be5150e
MD5 8d954fc02a4efc90a929ae77750045b5
BLAKE2b-256 e88361eea15181c8e2a226085f4f9b01d06fff7785d8783990fbf7e31d63aaa5

See more details on using hashes here.

File details

Details for the file cbitstruct-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cbitstruct-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c9c38dcd23e82d9aa77766841976fe5189d45e222cf1e516ba4a53ce349db560
MD5 ff793eea3c1524dfdde8ebb4080c56e1
BLAKE2b-256 d316b5046c62c11ebfaa397749333c21ff23cbfcafbcfc6bf9636c924952d282

See more details on using hashes here.

File details

Details for the file cbitstruct-1.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cbitstruct-1.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 13359a61531d7ebce2298362e38c7145005eceefa32d01dac2ec53cea2ec3725
MD5 ed2d269004aa6b2d70a947ffdfbfbf60
BLAKE2b-256 f4d326ca71738c8f143918aed224c285f4dda62507b8efc299d5c3b9c1f1c702

See more details on using hashes here.

File details

Details for the file cbitstruct-1.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cbitstruct-1.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 47e805f5300fc064d7d24a86e96617edb2bf85da598c8dfeaba939c3eeafefc0
MD5 931d86621c19a5ad5439ca405b9996bf
BLAKE2b-256 679e989e8b95c1b45e92bd2c59d848f85f9f0d7fcddc48ce1daba07ad935adc5

See more details on using hashes here.

File details

Details for the file cbitstruct-1.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cbitstruct-1.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d8bd95afce3327a675ac819878605d22eda0bb2a978528b367305603672dc4d2
MD5 f7a10f6141a778fe30c3d5660122c855
BLAKE2b-256 c611f740ccf65c50b20104550ebf15e2ad2b2062464f6138abf10ca915d6d782

See more details on using hashes here.

File details

Details for the file cbitstruct-1.1.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cbitstruct-1.1.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6ff61e58a494c92573d6db19c2a3d2384810d85c354f0fc735b368ac219e7e21
MD5 107c1ce68c9466f88f9807e448d9a36d
BLAKE2b-256 9b410d8f27276e463be7e5a3c3e5b18e5c2d7e5f6fddeee9443f29670b0f7c83

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page