This project benchmarks and compares the runtime performance of three different matrix multiplication implementations to understand the trade-offs between language choice and optimization:
- C Implementation - Low-level with
-O3optimization - Pure Python - Native nested lists with triple loops
- NumPy - Optimized C/Fortran backend (BLAS/LAPACK)
Goal: Demonstrate why NumPy is essential for numerical computing in Python by measuring execution times across matrix sizes from 64×64 to 2048×2048.
Homework 1/
├── Homework 1.ipynb # Main notebook with full analysis &visualizations
├── matrix_mult.c # C implementation source code
└── README.md # This file
File Descriptions:
Homework 1.ipynb: Complete benchmark suite with code, results, plots, and analysismatrix_mult.c: C implementation using triple nested loops with dynamic memory allocation
- Python 3.x
- GCC Compiler
- Jupyter Notebook
pip install numpy pandas matplotlib jupytergcc -O3 matrix_mult.c -o matrix_multOpen the Jupyter notebook and execute all cells:
jupyter notebook "Homework 1.ipynb"This will:
- Compile and test C implementation
- Run Pure Python benchmarks
- Run NumPy benchmarks
- Generate performance comparison plots
- Display detailed analysis
| Implementation | Execution Time | Speedup vs Python |
|---|---|---|
| NumPy | 39.5 ms | 5,680× faster |
| C | 3,154.8 ms | 71× faster |
| Pure Python | 224,311.3 ms | Baseline (1×) |
NumPy dominates - Even beats optimized C code (~80× faster)
C is fast - Significantly outperforms Pure Python
Pure Python is impractical - Orders of magnitude slower for large matrices
The notebook generates two main plots:
-
Execution Time vs Matrix Size (log-log scale)
- Demonstrates O(N³) complexity
- Shows exponential performance gaps
-
Speedup Factor Analysis
- NumPy vs Pure Python speedup
- C vs Pure Python speedup
- NumPy vs C speedup
Note: Both charts will be generated and displayed inline within the Homework 1.ipynb notebook after executing the corresponding code cells.
| Aspect | Pure Python | C | NumPy |
|---|---|---|---|
| Execution | Interpreted | Compiled | Compiled (C/Fortran) |
| Typing | Dynamic | Static | Static |
| Optimization | None | -O3 flag |
BLAS/LAPACK + SIMD |
| Memory | Scattered pointers | Contiguous | Cache-optimized blocks |
NumPy's secret: Uses decades-optimized BLAS/LAPACK libraries with SIMD vectorization and intelligent cache blocking - hard to replicate manually.
Author: Student name: 23120342 - Student ID: 23120342
Course: Programming for Data Science
Assignment: Homework 1 - Performance Benchmarking
- NumPy development team for the optimized library
- BLAS/LAPACK developers for foundational algorithms
- Course instructors for guidance
Contributions: This is an educational project. Feel free to fork and experiment with different matrix sizes or algorithms!
This project is created for educational purposes as part of a Programming for Data Science course assignment.
Usage: Free to use for learning and reference. Please cite if used in academic work.
Key Takeaway: Always use NumPy for numerical computing in Python - it's not optional, it's essential!