Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I compare python functions in terms of performance?

I have written 2 functions doing the exact same thing, but I don't know which one is faster and better. How do I compare these 2 functions to see which one is better in terms of performance and everything?

like image 792
alwbtc Avatar asked Oct 31 '11 16:10

alwbtc


2 Answers

The timeit module will do ya.

like image 157
kindall Avatar answered Oct 05 '22 01:10

kindall


Once you've found out which function is faster using the timeit module, you can also get more precise details of where the differences are by using the profile module.

like image 33
ekhumoro Avatar answered Oct 05 '22 02:10

ekhumoro