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.

Similar Reads

Method 1: Python time module

Time in Python is easy to implement and it can be used anywhere in a program to measure the execution time. By using timers we can get the exact time and we can improve the program where it takes too long. The time module provides the methods in order to profile a program....

Method 2: Python line_profiler

...

Method 3: Python cProfile

...

Contact Us