A Python benchmarking project I made that compares the speed of pure Python nested loops vs NumPy for matrix multiplication. The program asks the user to enter a matrix size, generates two random matrices of that size, multiplies them both ways, and prints how long each method took and how many times faster NumPy was.
- Make sure Python and NumPy are installed
- Run matrix_multiply.py
- Enter a matrix size when prompted (try 100, 200, or 500)
| Matrix Size | Python Time | NumPy Time | Speedup |
|---|---|---|---|
| 20x20 | 0.006s | 0.0001s | 52x faster |
| 200x200 | 5.68s | 0.013s | 420x faster |
| 500x500 | 74.88s | 0.367s | 204x faster |
NumPy is dramatically faster than pure Python for matrix multiplication because NumPy runs optimized C code under the hood. Pure Python relies on slow nested loops that scale poorly as matrix size grows.
- Python 3.13
- NumPy
- time module
- random module