Migrate Python data-processing code to Rust for better performance. This repository demonstrates a full Python-to-Rust rewrite: same logic (factorial), testing, linting, and benchmarking—useful for learning Rust migration and comparing Python vs Rust speed.
This project rewrites an existing Python script in Rust and compares performance. It is a practical example of:
- Code migration — Translating a Python data-processing script into idiomatic Rust while keeping behavior identical.
- Performance comparison — Measuring execution speed and resource usage of the Rust version vs the Python version.
Use this repo to learn how to rewrite Python in Rust, see Rust vs Python performance on a small workload, and follow a Python to Rust migration workflow with tests and tooling.
Prerequisites: Rust (and optionally Python 3 for the original script).
# Format, lint, test, and run the Rust program
make format
make lint
make test
make runRun the Python version:
make python_install # install Python deps
make python_test # run tests
make python_format # format with Black
make python_lint # lint with Ruff| Path | Purpose |
|---|---|
main.py, mylib/ |
Original Python script and library |
src/main.rs, src/lib.rs |
Rust equivalent (factorial logic) |
Makefile |
Commands for Rust and Python (format, lint, test, run) |
Cargo.toml |
Rust project and dependencies |
- Script selection — A small Python script (factorial/data-style processing) was chosen as the migration target.
- Rewrite in Rust — The script was reimplemented in Rust with the same behavior.
- Testing and debugging — Tests and manual checks ensure Rust output matches Python.
- Benchmarking — Execution time and resource usage are compared between Python and Rust.
- Documentation — Process and results are documented (including this README).
| Command | Description |
|---|---|
make format |
Format Rust code (cargo fmt) |
make lint |
Lint Rust code (Clippy) |
make test |
Run Rust tests |
make run |
Run the Rust binary |
make release |
Build release binary |
make python_install |
Install Python dependencies |
make python_test |
Run Python tests (pytest) |
make python_format |
Format Python with Black |
make python_lint |
Lint Python with Ruff |
KuchikiRenji
- Email: KuchikiRenji@outlook.com
- GitHub: github.com/KuchikiRenji
- Discord:
kuchiki_renji
See LICENSE in this repository.