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

Uploaded Source

Built Distributions

cbitstruct-1.0.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (71.5 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

cbitstruct-1.0.9-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.0.9-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (69.4 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

cbitstruct-1.0.9-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

File details

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

File metadata

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

File hashes

Hashes for cbitstruct-1.0.9.tar.gz
Algorithm Hash digest
SHA256 937c75caf1a438f5f49442c789cc171afb898c75ebf6ba7006c3b5f226255780
MD5 6f2d78c6cac7314895bd724f9b750120
BLAKE2b-256 b9e55562adfa22b709a6201e5e7b69d6b60439b009503bf556f9bbe110f1ddc8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cbitstruct-1.0.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b1b0b10599ae288adda8d9d8b282e12530da3bd4cd21dbdc8e6c8eb15674c653
MD5 4514342caba8b0eb129a573028ec15ce
BLAKE2b-256 537737c3aba0bebb3ad58dc37fd1f3e146fac7a105f70a6d339af9bb98f6e9ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cbitstruct-1.0.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d5335477855ab688e69fe896c0a41117fbf52ff16ae3ebf86ef4cbbd87c4c441
MD5 8ed78a859d3ceabd3cd4c788b144542f
BLAKE2b-256 b8c43af69df97d013bebc0a5f004b9167ffff855d6bdda32c99eaed8cf2324a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cbitstruct-1.0.9-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eec47ddb880ebb2581196dbfc6eaaeedbb9f3f801fb5837bc3a9dbb851336f6c
MD5 32900819a223e2ce31b38591ddeef965
BLAKE2b-256 14640cba480820be56a85dd8becc57662b0f5891b883fef7fd831dcac4b11e38

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cbitstruct-1.0.9-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c641ef289b3ad7a3c96a1f39d206e0401476b3b60c07f367aa735ffaa99c1eee
MD5 8a5b106641a70bd0a526ac79f8a402f9
BLAKE2b-256 d8246c07bed6602faa6395c669c3d761a0307eaf48a6d81d94ea85caa4083901

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