Speed Up Python With Rust
Channel: Nick Space Cowboy
Date: 2022-07-18

In this video we discuss how we can speed up our Python code using Rust code, Pyo3 (a Rust crate), and a tool called Maturin.

Python programs having slow performance is no secret. There are multiple ways that we can speed up our Python code, but one way to see our Python code perform better is to write a Python module in Rust.
Rust is a beloved, low-level language, that has a reputation for being blazingly fast. Using a Rust crate called Pyo3 and a tool called Maturin we can easily take our Rust code and compile it into a Python module that we can easily use in our Python code. This will allow us to take advantage of Rust's blazingly fast speeds in Python.
I explore these performance improvements by comparing random number generation between Python's standard random library, NumPy, and custom code written in Rust,

Check out Pyo3: https://pyo3.rs/main/module.html

Code used in this video: https://github.com/nkphysics/Exploring-Random

Table of Contents:
00:00 - Introduction
01:33 - Quick disclaimer
01:58 - General overview or random number generators being used
02:29 - Using Pyo3
03:41 - Using Maturin
04:57 - Further description of the tests
05:42 - Performance with Python Lists
06:27 - Performance with NumPy arrays
07:50 - Performance with Rust Vectors
12:15 - Rust vectors vs optimal use of NumPy
12:51 - Conclusions