Python line_profiler
Python provides a built-in module to measure execution time and the module name is LineProfiler.It gives a detailed report on the time consumed by a program.
Python3
# importing line_profiler module from line_profiler import LineProfiler def geek(rk): print (rk) rk = "geeks" profile = LineProfiler(geek(rk)) profile.print_stats() |
Output:
Timer unit: 4.27198e-10 s
Profiling in Python
Python provides many excellent modules to measure the statistics of a program. This makes us know where the program is spending too much time and what to do in order to optimize it. It is better to optimize the code in order to increase the efficiency of a program. So, perform some standard tests to ensure optimization and we can improve the program in order to increase efficiency. In this article, we will cover How do we profile a Python script to know where the program is spending too much time and what to do in order to optimize it.
Contact Us