Option 1: Profiling Code to Learn about Overall Performance in Real-Life Scenarios
This a great way of determining the impact of running your functions in real-life scenarios.
To learn more about your code performance, you can use Profiling.
Run the following command to evaluate function performance:
import cProfile
cProfile.run('function()')
This gives you valuable information such as; Total call count, cumulative time, times for each function call, and call count for each function.
Option 2: Investigating Spesific Function Call Duration
This is a great method to learn about function runtime duration.
Using decorator:
from functools import wraps
from time import time
def timing(f):
@wraps(f)
def wrap(*args, **kw):
ts = time()
result = f(*args, **kw)
te = time()
print 'func:%r args:[%r, %r] took: %2.4f sec' % \
(f.__name__, args, kw, te-ts)
return result
return wrap
Use it like this:
@timing
def function():
<code>