-
Notifications
You must be signed in to change notification settings - Fork 6
Home
Karl edited this page May 2, 2015
·
1 revision
The timeit module that comes with python is only useful for small bits of Python code not for functions.
This library solves that. It provides an intuitive way to measure the execution time of functions and compare the relative speed of two functions.
would you want to compare the relative speed of two functions? Because if you are optimizing your code you may want to know how much of a speed improvement you gained.
Pythonbenchmark allows this by letting you compare two functions which take the same input and measure which one gets the job done faster.
Additionally you can just put a decorator on the functions, pythonbenchmark will measure them and print out the execution time in the console. : The typical use case could be: You have functionX, and optimized functionX. Now you want to know if your modified version is faster.
![alt tag](https://github.com/Karlheinzniebuhr/pythonbenchmark/blob/master/test_files/test_compare.PNG)
![alt tag](https://github.com/Karlheinzniebuhr/pythonbenchmark/blob/master/test_files/test_decorator.PNG)
Adding support to compare multiple functions maybe? Any ideas are welcome
This library solves that. It provides an intuitive way to measure the execution time of functions and compare the relative speed of two functions.
would you want to compare the relative speed of two functions? Because if you are optimizing your code you may want to know how much of a speed improvement you gained.
Pythonbenchmark allows this by letting you compare two functions which take the same input and measure which one gets the job done faster.
Additionally you can just put a decorator on the functions, pythonbenchmark will measure them and print out the execution time in the console. : The typical use case could be: You have functionX, and optimized functionX. Now you want to know if your modified version is faster.
from pythonbenchmark import compare, measure
import time
a,b,c,d,e = 10,10,10,10,10
something = [a,b,c,d,e]
def myFunction(something):
time.sleep(0.4)
def myOptimizedFunction(something):
time.sleep(0.2)
# comparing test
compare(myFunction, myOptimizedFunction, 10, input)
Measuring execution time with the @measure decorator
from pythonbenchmark import compare, measure
import time
a,b,c,d,e = 10,10,10,10,10
something = [a,b,c,d,e]
@measure
def myFunction(something):
time.sleep(0.4)
@measure
def myOptimizedFunction(something):
time.sleep(0.2)
myFunction(input)
myOptimizedFunction(input)
Adding support to compare multiple functions maybe? Any ideas are welcome