{"id":16276663,"url":"https://github.com/virgesmith/pyo3-examples","last_synced_at":"2025-04-08T16:53:24.334Z","repository":{"id":87710800,"uuid":"592836275","full_name":"virgesmith/pyo3-examples","owner":"virgesmith","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-17T13:15:52.000Z","size":79,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-14T13:30:31.553Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/virgesmith.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":"2023-01-24T16:35:41.000Z","updated_at":"2024-11-17T13:15:56.000Z","dependencies_parsed_at":"2024-03-15T13:43:10.963Z","dependency_job_id":"275d1688-654f-4cd5-8a0a-5075dbd1b9a8","html_url":"https://github.com/virgesmith/pyo3-examples","commit_stats":null,"previous_names":["virgesmith/pyo3-examples"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virgesmith%2Fpyo3-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virgesmith%2Fpyo3-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virgesmith%2Fpyo3-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virgesmith%2Fpyo3-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/virgesmith","download_url":"https://codeload.github.com/virgesmith/pyo3-examples/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247888246,"owners_count":21012996,"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":[],"created_at":"2024-10-10T18:49:46.776Z","updated_at":"2025-04-08T16:53:24.309Z","avatar_url":"https://github.com/virgesmith.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pyo3-examples\n\nExample of a rust implementation of certain python constructs.\n\nThe aims are twofold:\n\n- replicate the functionality of the C++/pybind11 equivalent [here](https://github.com/virgesmith/pybind11-examples), and compare the ease of implementation\n- compare performance by implementing the some basic prime number generation and factorisation algorithms in python, C++ and rust.\n\n## build\n\n```sh\npip install -e .[dev]\n```\n\n## test\n\n```sh\npytest\n```\n\n## compare\n\nInstall [pybind11-examples](https://github.com/virgesmith/pybind11-examples) in the same env.\n\n```sh\nperf-test\n```\n\nto run performance tests.\n\n## package\n\n```sh\nmaturin build --release\n```\n\n## feature completeness\n\nCompared to [pybind11-examples](https://github.com/virgesmith/pybind11-examples). When I say easier I mean easier **in the end** ;)\n\n- [X] generators. Ever so slightly easier than pybind11 thanks to `PyErr::from_type`.\n- [X] `__init_subclass__`. Was actually easier than in C++/pybind11, which requires a workaround for classmethods.\n- [X] decorators. Definitely more tricky, but got there in the end thanks to SO.\n- [X] context managers. More boilerplate needed - in C++ I can just selectively expose template specialisations to python.\n- [ ] constants\n- [ ] enums\n- [ ] vectorised functions\n- [X] type annotations (manually)\n\n## performance comparison\n\nrust initially seemed faster but after some performance improvements of the algorithms (in all languages), overall speed is much improved and C++ has more than caught up. Here's the latest results, times are in milliseconds:\n\nUpdated results:\n\n| function      | parameters                           |   rust |   python |   C++ |\n|:--------------|:-------------------------------------|-------:|---------:|------:|\n| nth_prime     | (100000,)                            |      8 |       93 |     5 |\n| nth_prime     | (1000000,)                           |     87 |     1031 |    87 |\n| prime_factors | (2199023255551,)                     |      3 |      709 |     6 |\n| prime_factors | (10000000000000068,)                 |    769 |      nan |   578 |\n| PrimeRange    | (1000000000000000, 1000000000001000) |    322 |      nan |   290 |\n| is_prime      | (10000000000000061,)                 |    764 |      nan |   588 |\n\nrustc 1.76, py03 0.20.3\ng++ 11.4, pybind11 2.11.1\ncpython 3.12\n\n## see also\n\n[https://www.maturin.rs/tutorial.html](https://www.maturin.rs/tutorial.html)\n\n[https://pyo3.rs](https://pyo3.rs)\n\n[https://docs.rs/pyo3/latest/pyo3/](https://docs.rs/pyo3/latest/pyo3/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirgesmith%2Fpyo3-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvirgesmith%2Fpyo3-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirgesmith%2Fpyo3-examples/lists"}