From the course: Faster Python Code

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

line_profiler

line_profiler - Python Tutorial

From the course: Faster Python Code

Start my 1-month free trial

line_profiler

- [Instructor] Sometimes a finer granularity than a function is required. In these cases, line_profiler can be used. Line_profiler is not in the standard library. You can install it with pip or Conda. When we pip install line_profiler, we also get the command-line program called kernprof which is used to run our program under the line_profiler. Line_profiler doesn't automatically profile anything. You need to tell it which functions you'd like to monitor. We do this by adding a profile decorator. If you look at our code for logging in user, which you can find in the exercise file, at line 26 we have a login function. We want to profile it, so we'll add a profile decorator. A decorator lets you extends a function behavior without changing its code. If you're not familiar with Python decorators, check out our Python essential training course. And now, once we added the profile decorator and save the file, we are going to switch…

Contents