How to measure the duration of a function call or code block in python

The simple way to measure the duration of function call in python using context management.

Some times we may encounter the situation where we need to know total time taken by the function call. Here is the code which is pretty much handy and simple to measure the duration of function call  or  time taken by the function(call) in python

Here is how you apply the above code to get the time taken by the function call


 

Output would look like as follows,