Functions of profilehooks
Let's learn about profilehooks and how it helps.
We'll cover the following...
The last 3rd party package that we will look at in this chapter is
called profilehooks
. It is a collection of decorators specifically
designed for profiling functions.
Let’s start with profilehooks
To install profilehooks
, just do the
following:
Press + to interact
pip3 install profilehooks
Now that we have it installed, let’s re-use the example from the last lesson and modify it slightly to use profilehooks
:
Press + to interact
# profhooks.pyfrom profilehooks import profile#@profiledef mem_func():t_range= 1000import randomrange_num1 = [random.randint(1,10) for i in range(t_range)]range_num2 = [random.randint(1,10) for i in range(t_range)]sum_range = [range_num1[i]+range_num2[i] for i in range(t_range)]total_of_ranges = sum(sum_range)print(total_of_ranges)if __name__ == "__main__":mem_func()
Testing the
...Access this course and 1400+ top-rated courses and projects.