bencode-c


Namebencode-c JSON
Version 0.0.14 PyPI version JSON
download
home_pageNone
SummaryA fast and correct bencode serialize/deserialize library
upload_time2024-05-25 19:43:31
maintainerNone
docs_urlNone
authorNone
requires_python<4.0,>=3.8
licenseMIT
keywords bencode bittorrent bit-torrent serialize deserialize p2p
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # bencode-c

bencode serialize/deserialize written in native c extension.

```shell
pip install bencode-c
```

```python
import bencode_c

# NOTICE: we decode bencode bytes to bytes, not str.
assert bencode_c.bdecode(b'd5:hello5:worlde') == {b'hello': b'world'}

assert bencode_c.bencode(...) == b'...'
```

## Benchmark

this maybe the fastest bencode library in python.

compared packages:

- `abi3`: native c extension (this package) [bencode-c](https://pypi.org/project/bencode-c)
- `py`: pure python implement [bencode-py](https://pypi.org/project/bencode-py)
- `cy`: cython implement [fast-bencode](https://pypi.org/project/fast-bencode)
- `mypy`: pure python implement with mypyc [bencode2](https://pypi.org/project/bencode2)

test cases are 40 torrents from real world.

(windows, python3.10 AMD R7 5800X)

### Decode

```
------------------------------------------------------------ benchmark 'case=decode': 4 tests ------------------------------------------------------------
Name (time in us)                      Mean                    Min                    Max                 Median              StdDev            Iterations
----------------------------------------------------------------------------------------------------------------------------------------------------------
test_benchmark[decode-abi3]      1,024.6516 (1.0)         987.3901 (1.0)       1,097.5088 (1.0)       1,010.7185 (1.0)       42.6630 (1.0)            1013
test_benchmark[decode-cy]        2,471.1399 (2.41)      2,269.6842 (2.30)      2,592.6601 (2.36)      2,484.0398 (2.46)     121.1285 (2.84)           1000
test_benchmark[decode-mypy]      7,451.1057 (7.27)      7,319.7134 (7.41)      7,697.5504 (7.01)      7,399.4402 (7.32)     149.9720 (3.52)            127
test_benchmark[decode-py]       21,020.7260 (20.51)    20,832.5390 (21.10)    21,180.5220 (19.30)    21,047.4730 (20.82)    139.9841 (3.28)            100
----------------------------------------------------------------------------------------------------------------------------------------------------------
```

### Encode

```
--------------------------------------------------- benchmark 'case=encode': 4 tests ---------------------------------------------------
Name (time in ms)                  Mean                Min                Max             Median            StdDev            Iterations
----------------------------------------------------------------------------------------------------------------------------------------
test_benchmark[encode-abi3]      4.2812 (1.0)       4.1505 (1.0)       4.3833 (1.0)       4.2897 (1.0)      0.0843 (1.56)           1000
test_benchmark[encode-mypy]      5.0277 (1.17)      4.9340 (1.19)      5.0887 (1.16)      5.0244 (1.17)     0.0606 (1.12)           1000
test_benchmark[encode-cy]        5.7779 (1.35)      5.7304 (1.38)      5.8682 (1.34)      5.7562 (1.34)     0.0541 (1.0)             178
test_benchmark[encode-py]       13.7456 (3.21)     13.5073 (3.25)     14.0211 (3.20)     13.5974 (3.17)     0.2524 (4.67)            100
----------------------------------------------------------------------------------------------------------------------------------------
```

(linux, python3.10, Intel G6405)

### Decode

```
--------------------------------------------------- benchmark 'case=decode': 4 tests ---------------------------------------------------
Name (time in ms)                  Mean                Min                Max             Median            StdDev            Iterations
----------------------------------------------------------------------------------------------------------------------------------------
test_benchmark[decode-abi3]      1.9905 (1.0)       1.6988 (1.0)       2.4797 (1.0)       1.9208 (1.0)      0.3053 (1.0)             121
test_benchmark[decode-cy]        3.1906 (1.60)      2.6953 (1.59)      3.6342 (1.47)      3.2118 (1.67)     0.3971 (1.30)            100
test_benchmark[decode-mypy]     12.7124 (6.39)     11.4128 (6.72)     14.8851 (6.00)     12.4180 (6.46)     1.3009 (4.26)             18
test_benchmark[decode-py]       36.5785 (18.38)    33.5474 (19.75)    44.7655 (18.05)    34.5241 (17.97)    4.7173 (15.45)            10
----------------------------------------------------------------------------------------------------------------------------------------
```

### Encode

```
--------------------------------------------------- benchmark 'case=encode': 4 tests ---------------------------------------------------
Name (time in ms)                  Mean                Min                Max             Median            StdDev            Iterations
----------------------------------------------------------------------------------------------------------------------------------------
test_benchmark[encode-abi3]      4.5476 (1.0)       4.2847 (1.0)       4.9841 (1.0)       4.4301 (1.0)      0.2711 (1.0)             100
test_benchmark[encode-cy]        6.3922 (1.41)      5.9589 (1.39)      6.8652 (1.38)      6.1731 (1.39)     0.4102 (1.51)            100
test_benchmark[encode-mypy]      7.8197 (1.72)      7.2574 (1.69)      8.3987 (1.69)      7.8091 (1.76)     0.4947 (1.82)            100
test_benchmark[encode-py]       23.9431 (5.26)     23.4045 (5.46)     24.2830 (4.87)     24.0749 (5.43)     0.3818 (1.41)             10
----------------------------------------------------------------------------------------------------------------------------------------
```

# development

```shell
git clone -r https://github.com/trim21/bencode-c bencode-c
cd bencode-c
python -m venv .venv
# enable venv
source .venv/bin/activate

pip install -e .

pytest -sv
```

`CMakeLists.txt` is for IDE to find includes, not for building files.

use `setup.py` to build python extension.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "bencode-c",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "bencode, bittorrent, bit-torrent, serialize, deserialize, p2p",
    "author": null,
    "author_email": "trim21 <trim21me@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/98/bd/41e0cac72d96c89aa9bf52011c73598dd440b95affb6dcf508d3b3a7cd3d/bencode_c-0.0.14.tar.gz",
    "platform": null,
    "description": "# bencode-c\n\nbencode serialize/deserialize written in native c extension.\n\n```shell\npip install bencode-c\n```\n\n```python\nimport bencode_c\n\n# NOTICE: we decode bencode bytes to bytes, not str.\nassert bencode_c.bdecode(b'd5:hello5:worlde') == {b'hello': b'world'}\n\nassert bencode_c.bencode(...) == b'...'\n```\n\n## Benchmark\n\nthis maybe the fastest bencode library in python.\n\ncompared packages:\n\n- `abi3`: native c extension (this package) [bencode-c](https://pypi.org/project/bencode-c)\n- `py`: pure python implement [bencode-py](https://pypi.org/project/bencode-py)\n- `cy`: cython implement [fast-bencode](https://pypi.org/project/fast-bencode)\n- `mypy`: pure python implement with mypyc [bencode2](https://pypi.org/project/bencode2)\n\ntest cases are 40 torrents from real world.\n\n(windows, python3.10 AMD R7 5800X)\n\n### Decode\n\n```\n------------------------------------------------------------ benchmark 'case=decode': 4 tests ------------------------------------------------------------\nName (time in us)                      Mean                    Min                    Max                 Median              StdDev            Iterations\n----------------------------------------------------------------------------------------------------------------------------------------------------------\ntest_benchmark[decode-abi3]      1,024.6516 (1.0)         987.3901 (1.0)       1,097.5088 (1.0)       1,010.7185 (1.0)       42.6630 (1.0)            1013\ntest_benchmark[decode-cy]        2,471.1399 (2.41)      2,269.6842 (2.30)      2,592.6601 (2.36)      2,484.0398 (2.46)     121.1285 (2.84)           1000\ntest_benchmark[decode-mypy]      7,451.1057 (7.27)      7,319.7134 (7.41)      7,697.5504 (7.01)      7,399.4402 (7.32)     149.9720 (3.52)            127\ntest_benchmark[decode-py]       21,020.7260 (20.51)    20,832.5390 (21.10)    21,180.5220 (19.30)    21,047.4730 (20.82)    139.9841 (3.28)            100\n----------------------------------------------------------------------------------------------------------------------------------------------------------\n```\n\n### Encode\n\n```\n--------------------------------------------------- benchmark 'case=encode': 4 tests ---------------------------------------------------\nName (time in ms)                  Mean                Min                Max             Median            StdDev            Iterations\n----------------------------------------------------------------------------------------------------------------------------------------\ntest_benchmark[encode-abi3]      4.2812 (1.0)       4.1505 (1.0)       4.3833 (1.0)       4.2897 (1.0)      0.0843 (1.56)           1000\ntest_benchmark[encode-mypy]      5.0277 (1.17)      4.9340 (1.19)      5.0887 (1.16)      5.0244 (1.17)     0.0606 (1.12)           1000\ntest_benchmark[encode-cy]        5.7779 (1.35)      5.7304 (1.38)      5.8682 (1.34)      5.7562 (1.34)     0.0541 (1.0)             178\ntest_benchmark[encode-py]       13.7456 (3.21)     13.5073 (3.25)     14.0211 (3.20)     13.5974 (3.17)     0.2524 (4.67)            100\n----------------------------------------------------------------------------------------------------------------------------------------\n```\n\n(linux, python3.10, Intel G6405)\n\n### Decode\n\n```\n--------------------------------------------------- benchmark 'case=decode': 4 tests ---------------------------------------------------\nName (time in ms)                  Mean                Min                Max             Median            StdDev            Iterations\n----------------------------------------------------------------------------------------------------------------------------------------\ntest_benchmark[decode-abi3]      1.9905 (1.0)       1.6988 (1.0)       2.4797 (1.0)       1.9208 (1.0)      0.3053 (1.0)             121\ntest_benchmark[decode-cy]        3.1906 (1.60)      2.6953 (1.59)      3.6342 (1.47)      3.2118 (1.67)     0.3971 (1.30)            100\ntest_benchmark[decode-mypy]     12.7124 (6.39)     11.4128 (6.72)     14.8851 (6.00)     12.4180 (6.46)     1.3009 (4.26)             18\ntest_benchmark[decode-py]       36.5785 (18.38)    33.5474 (19.75)    44.7655 (18.05)    34.5241 (17.97)    4.7173 (15.45)            10\n----------------------------------------------------------------------------------------------------------------------------------------\n```\n\n### Encode\n\n```\n--------------------------------------------------- benchmark 'case=encode': 4 tests ---------------------------------------------------\nName (time in ms)                  Mean                Min                Max             Median            StdDev            Iterations\n----------------------------------------------------------------------------------------------------------------------------------------\ntest_benchmark[encode-abi3]      4.5476 (1.0)       4.2847 (1.0)       4.9841 (1.0)       4.4301 (1.0)      0.2711 (1.0)             100\ntest_benchmark[encode-cy]        6.3922 (1.41)      5.9589 (1.39)      6.8652 (1.38)      6.1731 (1.39)     0.4102 (1.51)            100\ntest_benchmark[encode-mypy]      7.8197 (1.72)      7.2574 (1.69)      8.3987 (1.69)      7.8091 (1.76)     0.4947 (1.82)            100\ntest_benchmark[encode-py]       23.9431 (5.26)     23.4045 (5.46)     24.2830 (4.87)     24.0749 (5.43)     0.3818 (1.41)             10\n----------------------------------------------------------------------------------------------------------------------------------------\n```\n\n# development\n\n```shell\ngit clone -r https://github.com/trim21/bencode-c bencode-c\ncd bencode-c\npython -m venv .venv\n# enable venv\nsource .venv/bin/activate\n\npip install -e .\n\npytest -sv\n```\n\n`CMakeLists.txt` is for IDE to find includes, not for building files.\n\nuse `setup.py` to build python extension.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A fast and correct bencode serialize/deserialize library",
    "version": "0.0.14",
    "project_urls": null,
    "split_keywords": [
        "bencode",
        " bittorrent",
        " bit-torrent",
        " serialize",
        " deserialize",
        " p2p"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f44e1bb07a37038aa91336f68c329a015c163461ce8f35f273f86375a17e291f",
                "md5": "284b7910e78727dbf8575f707598f59a",
                "sha256": "e93e210c3d560d9af30976d9198d5c9538ce003da1dd8ddef9682b75a9c27532"
            },
            "downloads": -1,
            "filename": "bencode_c-0.0.14-cp38-abi3-macosx_10_9_x86_64.whl",
            "has_sig": false,
            "md5_digest": "284b7910e78727dbf8575f707598f59a",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": "<4.0,>=3.8",
            "size": 20906,
            "upload_time": "2024-05-25T19:43:22",
            "upload_time_iso_8601": "2024-05-25T19:43:22.301241Z",
            "url": "https://files.pythonhosted.org/packages/f4/4e/1bb07a37038aa91336f68c329a015c163461ce8f35f273f86375a17e291f/bencode_c-0.0.14-cp38-abi3-macosx_10_9_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "373581916e8a6c6d3fc2e097ad11629532fa74d6d7baa80c7928d06f2655d883",
                "md5": "8bbd5c426c17d7a22ce1398b29b34239",
                "sha256": "1a3323f2537463d2deb2c4e76b1418d72da06e4e9dbb830e5b003ca6bd8d1551"
            },
            "downloads": -1,
            "filename": "bencode_c-0.0.14-cp38-abi3-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "8bbd5c426c17d7a22ce1398b29b34239",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": "<4.0,>=3.8",
            "size": 20668,
            "upload_time": "2024-05-25T19:43:24",
            "upload_time_iso_8601": "2024-05-25T19:43:24.509191Z",
            "url": "https://files.pythonhosted.org/packages/37/35/81916e8a6c6d3fc2e097ad11629532fa74d6d7baa80c7928d06f2655d883/bencode_c-0.0.14-cp38-abi3-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ab72c1cb81ab02dd66cf9e443aa901fc9c6e35b23ae4861c52dff9b4dbb6439a",
                "md5": "d319fd841e4f04fbbe170801974d5f84",
                "sha256": "23754d45f9ad456d3aa666d804caafac88f9e7a8d1bd98888a0774035e3a2c3e"
            },
            "downloads": -1,
            "filename": "bencode_c-0.0.14-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "d319fd841e4f04fbbe170801974d5f84",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": "<4.0,>=3.8",
            "size": 56742,
            "upload_time": "2024-05-25T19:43:26",
            "upload_time_iso_8601": "2024-05-25T19:43:26.048292Z",
            "url": "https://files.pythonhosted.org/packages/ab/72/c1cb81ab02dd66cf9e443aa901fc9c6e35b23ae4861c52dff9b4dbb6439a/bencode_c-0.0.14-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a3a91536b7a8385a9f6cec83e429e6cf87e9d729d7e27518c826d985bdab2715",
                "md5": "c3a2946ab312094f7bb7d21836dac8c6",
                "sha256": "57d7ebcc5eba21acd812a2899ce02b4e04235a7f4008089ada83bb07e7942e5b"
            },
            "downloads": -1,
            "filename": "bencode_c-0.0.14-cp38-abi3-musllinux_1_2_x86_64.whl",
            "has_sig": false,
            "md5_digest": "c3a2946ab312094f7bb7d21836dac8c6",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": "<4.0,>=3.8",
            "size": 55460,
            "upload_time": "2024-05-25T19:43:27",
            "upload_time_iso_8601": "2024-05-25T19:43:27.544950Z",
            "url": "https://files.pythonhosted.org/packages/a3/a9/1536b7a8385a9f6cec83e429e6cf87e9d729d7e27518c826d985bdab2715/bencode_c-0.0.14-cp38-abi3-musllinux_1_2_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "414438980767780facd5fa11247634b5e1681aa86d1a971cfc74b30e2d477acf",
                "md5": "d04fdb0af29a920ef046e16b02379a80",
                "sha256": "83fbb1746deae6f8f6f416da867a9f88974b5efcb73a00a7f1f8c90d1d0514a6"
            },
            "downloads": -1,
            "filename": "bencode_c-0.0.14-cp38-abi3-win32.whl",
            "has_sig": false,
            "md5_digest": "d04fdb0af29a920ef046e16b02379a80",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": "<4.0,>=3.8",
            "size": 22562,
            "upload_time": "2024-05-25T19:43:29",
            "upload_time_iso_8601": "2024-05-25T19:43:29.089876Z",
            "url": "https://files.pythonhosted.org/packages/41/44/38980767780facd5fa11247634b5e1681aa86d1a971cfc74b30e2d477acf/bencode_c-0.0.14-cp38-abi3-win32.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d31f405b8530ab949e569a821377f2a521c70f68065ad85b21a1144c593922a7",
                "md5": "bf2b72421564b15d1deab3e5c65dad33",
                "sha256": "e5ca6f49df9b390b20306bf2719b0d5a02160673bae678a896a89c32d3cc40a8"
            },
            "downloads": -1,
            "filename": "bencode_c-0.0.14-cp38-abi3-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "bf2b72421564b15d1deab3e5c65dad33",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": "<4.0,>=3.8",
            "size": 23119,
            "upload_time": "2024-05-25T19:43:30",
            "upload_time_iso_8601": "2024-05-25T19:43:30.516261Z",
            "url": "https://files.pythonhosted.org/packages/d3/1f/405b8530ab949e569a821377f2a521c70f68065ad85b21a1144c593922a7/bencode_c-0.0.14-cp38-abi3-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "98bd41e0cac72d96c89aa9bf52011c73598dd440b95affb6dcf508d3b3a7cd3d",
                "md5": "7afd84036fb3ec4050ea8747c30cc0ee",
                "sha256": "8bc5e6f71b67776020c2bdd036cc3716dc8e28640bc987debb6bd6b9c7931396"
            },
            "downloads": -1,
            "filename": "bencode_c-0.0.14.tar.gz",
            "has_sig": false,
            "md5_digest": "7afd84036fb3ec4050ea8747c30cc0ee",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 14459,
            "upload_time": "2024-05-25T19:43:31",
            "upload_time_iso_8601": "2024-05-25T19:43:31.393400Z",
            "url": "https://files.pythonhosted.org/packages/98/bd/41e0cac72d96c89aa9bf52011c73598dd440b95affb6dcf508d3b3a7cd3d/bencode_c-0.0.14.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-25 19:43:31",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "bencode-c"
}
        
Elapsed time: 0.26062s