{"id":17362797,"url":"https://github.com/trim21/bencode-c","last_synced_at":"2025-03-24T01:43:13.750Z","repository":{"id":240806930,"uuid":"803517052","full_name":"trim21/bencode-c","owner":"trim21","description":"python bencode serialize/deserialize written in native c extension.","archived":false,"fork":false,"pushed_at":"2024-05-22T21:01:22.000Z","size":652,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-05-23T00:16:40.155Z","etag":null,"topics":["bencode","cpython","python"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trim21.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-20T21:53:11.000Z","updated_at":"2024-05-28T11:20:35.369Z","dependencies_parsed_at":"2024-05-28T11:30:45.205Z","dependency_job_id":null,"html_url":"https://github.com/trim21/bencode-c","commit_stats":null,"previous_names":["trim21/bencode-c"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trim21%2Fbencode-c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trim21%2Fbencode-c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trim21%2Fbencode-c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trim21%2Fbencode-c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trim21","download_url":"https://codeload.github.com/trim21/bencode-c/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245195925,"owners_count":20575936,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bencode","cpython","python"],"created_at":"2024-10-15T19:43:24.702Z","updated_at":"2025-03-24T01:43:13.712Z","avatar_url":"https://github.com/trim21.png","language":"C","readme":"# 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","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrim21%2Fbencode-c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrim21%2Fbencode-c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrim21%2Fbencode-c/lists"}