From the course: Faster Python Code

Unlock the full course today

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

CPU profiling

CPU profiling - Python Tutorial

From the course: Faster Python Code

Start my 1-month free trial

CPU profiling

- [Instructor] A profiler monitors the execution of your code and records where it spends its time. There are several profilers in the Python standard typer. cProfile, which is a deterministic profile is currently recommended by Python. Deterministic profiler record every function call and return, as well as exceptions. This is in contrast to statistical profilers, which record where the program is at small intervals. The documentation on the Python profilers is great and include important information on their limitation. Do read it. The profile generates a file with statistics on the run time and we use the pstats module to display them. The basic display is textual, but there are visual displays as well. Let's say we have a system that checks user login. To be secure, we store the user password in an encrypted form in a database. When the user logs in, we encrypt the password sent and compare it with the one stored in the database. Here is the code which you can find in the exercise…

Contents