July 18, 2014 | Python |

Plotting Algorithmic Time Complexity of a Function using Python

I have been reading Miller & Ranum's e-book on Python/Algorithms. (A superb book which is also free online.) While looking through their chapter on Algorithm Analysis, I took their idea of using the Python Timer and timeit methods a bit forward to create a simple plotting scheme using matplotlib.

Here is the code. You can add in your own function here and plot the time complexity.

The code is quite simple. Perhaps the only interesting thing here is the use of partial to pass in the function and the N parameter into Timer.

Here is the output.

Have fun! ;-)


Need help with a hardware project or product? Drop us an email at We offer consulting services on AVR and Nordic nRF BLE - hardware design, firmware development, prototyping, PCB design/assembly, sourcing and manufacturing. We can help you bring your product to market!


We love hearing from our readers. Email us at for questions or comments on this article. If you found this article useful, please support us by buying some of our hardware products.

Please sign up for updates

Once in a while, we will send you an email update on the latest Electronut Labs projects and products. Your email address will never be shared or abused, ever.

2016 Electronut Labs. All rights reserved.