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.2.0.tar.gz (29.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cbitstruct-1.2.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (71.7 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

cbitstruct-1.2.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (71.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

cbitstruct-1.2.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (72.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

cbitstruct-1.2.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (71.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

cbitstruct-1.2.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (69.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

cbitstruct-1.2.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (69.7 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

cbitstruct-1.2.0-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (69.6 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

File details

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

File metadata

  • Download URL: cbitstruct-1.2.0.tar.gz
  • Upload date:
  • Size: 29.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cbitstruct-1.2.0.tar.gz
Algorithm Hash digest
SHA256 eb7b45813c708ad9292dca23193e3c799b33eee773460f87c02fa8d660586dbf
MD5 49f7020f8bd305bfe291f98d0826a8fe
BLAKE2b-256 84ef358d974f04504a1672ee20ade1ad20eb6d8e5728660f6651666300af5a11

See more details on using hashes here.

Provenance

The following attestation bundles were made for cbitstruct-1.2.0.tar.gz:

Publisher: build_and_publish.yml on qchateau/cbitstruct

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cbitstruct-1.2.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cbitstruct-1.2.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 50c72404e4d384832af0c7fa2f9086f60505df29fb807484e29ef7c3cc3390cc
MD5 49fc53aed54ac87fd735cfceaf6edd04
BLAKE2b-256 8274f13ba5db0b01a240aa6da63bc8c336375cd1e32ba3ee77f0931e0169d372

See more details on using hashes here.

Provenance

The following attestation bundles were made for cbitstruct-1.2.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_and_publish.yml on qchateau/cbitstruct

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cbitstruct-1.2.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cbitstruct-1.2.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 266ba9424b873dde310617693b22fdd2f35041dca47973dcd00c028ce41e4e86
MD5 0afbda51e1cc25409c37a2e1757b0f18
BLAKE2b-256 d43cc81c1fc1b652219777028f8192127580b9861c0be553c589ff240a2de811

See more details on using hashes here.

Provenance

The following attestation bundles were made for cbitstruct-1.2.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_and_publish.yml on qchateau/cbitstruct

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cbitstruct-1.2.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cbitstruct-1.2.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 53cfa89b6ccd37ace3a838b2c6df84010b0a8605ebc6772737355c68e1434dcb
MD5 ddbf495a276309c51d2bdaaf61f75538
BLAKE2b-256 1b82a10383c00dad98dbb0bf2fa7b499b6ac8787110be90a1bef67f995c9a8c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for cbitstruct-1.2.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_and_publish.yml on qchateau/cbitstruct

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cbitstruct-1.2.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cbitstruct-1.2.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c7fc6e6573aa423e6b886ed1632c5d5082ae9ce686dc478297e1ca5ad34a968a
MD5 fd88cff2f24cd4c4212b3eeaa665e105
BLAKE2b-256 1084a66f1d7a110e125cca713c8601bfc18ccffc16e92714274ab8a66ce78e5f

See more details on using hashes here.

Provenance

The following attestation bundles were made for cbitstruct-1.2.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_and_publish.yml on qchateau/cbitstruct

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cbitstruct-1.2.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cbitstruct-1.2.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 811c346f851bb2df05c3e61537938e30a426a81aa168ad86ca60fc4efc25b982
MD5 14d72748c9c3bbb2743cd1c9dcd5943d
BLAKE2b-256 ed524519260554e154b85a69ff893a78038f0eb129c11b3296acf3c993bdadd4

See more details on using hashes here.

Provenance

The following attestation bundles were made for cbitstruct-1.2.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_and_publish.yml on qchateau/cbitstruct

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cbitstruct-1.2.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cbitstruct-1.2.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ac67006f827bd559f924c1ff7dfd98c398cca058ba14142f157710b6886fbd98
MD5 2936d87f852794f3ba855731a57d5025
BLAKE2b-256 80d4dee12497734cf0aba78f7492122fe9dfedebf482c6a3b444f7144c67937e

See more details on using hashes here.

Provenance

The following attestation bundles were made for cbitstruct-1.2.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_and_publish.yml on qchateau/cbitstruct

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cbitstruct-1.2.0-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cbitstruct-1.2.0-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 daaf69ed4d97cf63d265a3d1cae571bdb4967cc942c30b0898bdb6c841d67c10
MD5 5e92fd5628b55352faf91967997131c5
BLAKE2b-256 df26762066947819fa1fa2363a1723275fd7d098fe602848b82ee3faa9751c07

See more details on using hashes here.

Provenance

The following attestation bundles were made for cbitstruct-1.2.0-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_and_publish.yml on qchateau/cbitstruct

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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