Skip to content

cwilliams-systems/NumPy-vs-Python-Matrix-Multiply

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

NumPy vs Python Matrix Multiplication Benchmark

What it does

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.

How to run it

  • Make sure Python and NumPy are installed
  • Run matrix_multiply.py
  • Enter a matrix size when prompted (try 100, 200, or 500)

Results

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

What I learned

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.

Technologies I used

  • Python 3.13
  • NumPy
  • time module
  • random module

About

Benchmarking NumPy vs pure Python matrix multiplication

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages