Python script for data processing in Rust, highlighting the improvements in speed and resource usage
The repo focuses towards comparing improvements in speed and resource usage for using rust against python.
I used criterion for Rust and pytest-benchmark for Python for benchmarking. Rust took 130ms and Python took 767ms to execute the same code. Rust around 6 times faster to Calculate sum of squares for the first 10 million natural numbers as compared to python.
To execute rust file :
- Install Rust (curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh)
- Install the rust-analyzer extension
- A good way to create Rust program is to use Cargo to scaffold a new project by typing cargo new. This will create a simple Hello World program along with a default Cargo.toml dependency file. You pass cargo new the folder where you'd like to create the project.
- cargo new rust_time
- Cargo new creates a project with a main.rs source code file and Cargo.toml Cargo manifest file.
- main.rs has the program's entry function main() and prints "Hello, world!" to the console using println!.
- The output :
To execute python file :
- Install pytest-benchmark
- run the command pytest python.py
- The output :
-
requirements.txt - Contains all the required python packages
-
Makfefile - Using make to automate different parts of developing a Python project, like -
1. running tests 2. cleaning builds 3. installing dependencies
Integrating it into my routine, so can save time and avoid errors.
-
.github/workflows - This directory in a Python project (or any GitHub repository) is used for creating and storing GitHub Actions workflows. GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform provided by GitHub. The workflow is triggered on pushes to the main branch. It sets up :
1. Python environment 2. Installs project dependencies 3. Install packages 4. Linitng 5. Runs tests 6. Format