Skip to main content

Posts

Showing posts from October, 2016

The Magic of Numba and Python

Python is a great programming language. It's primary merits are readability and the numerous packages that are available online. However, being an interpreted language the speed of execution is always an issue. Here is a simple example of a piece of code written in Python that tries to add two numbers from a grid. #!/usr/bin/python def overlap_pp(x,y): count = 0 for i in range(x): for j in range(y): count += i + j return count for _ in range(1000): q = overlap_pp(500,500) If you run the above script (saved as n.py) on the command line terminal with the time command you should see some numbers like the below time ./n.py real 0m22.379s user 0m22.363s sys 0m0.407s The process running on one processor took about 22 seconds to complete the run. Now lets do something seemingly magical. Lets add a decorator. Decorators are python speak for a mechanism to do wrapper functions. The decorator we are going to add is '@jit'. The code looks l