Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Profiling Performance in Python (Summary)

You’ve learned about profiling a program’s performance in order to find hot spots or performance bottlenecks. High memory consumption, inefficient CPU use, and excessive function calls can be common indicators of potential issues in your software that need improvement.

In this video course, you:

  • Learned that it’s important to profile before you optimize, so you can avoidguessing and focus on real bottlenecks
  • Saw how profiling helps pinpoint which parts of your code are slowing thingsdown
  • Used Python’s timeit module to measure the average runtime of a smallcode snippet
  • Worked with cProfile, a deterministic profiler that records every functioncall and shows exactly how much time is spent in each one
  • Tried out Pyinstrument, a statistical profiler that samples your program atregular intervals to show where most of the time is spent
Download

Cheat Sheet (.zip)

39.4 KB
Download

Course Slides (.pdf)

4.0 MB

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member? Sign-In

00:00 Well done. You just completed this video course and learned a lot about profiling. Let’s see what you accomplished.

00:08 You learned that it’s important to profile before you optimize so you can stop guessing and focus on the real performance issues. You saw how profiling helps you pinpoint exactly which parts of your code are slowing things down.

00:23 Then you used Python’s timeit module to measure the average runtime of a small code snippet. After that, you worked with cProfile, which is a deterministic profiler that tracks every function call and shows how much time each one takes.

00:39 And finally, you tried out Pyinstrument, a statistical profiler that samples your program at regular intervals to reveal where most of the time is spent. And now you’re ready to profile your own code.

00:53 If you want to keep learning, here are some Real Python articles you might like. If you want to dive deeper into profiling and explore more advanced tools, check out Profiling in Python: How to Find Performance Bottlenecks.

01:07 This article covers all the tools you tried out here, and a few additional ones, including perf, which gives you low-level details about your program, including hardware events and system calls.

01:20 If you’re curious about Python’s timer functions and want to learn more about timeit, take a look at Python Timer Functions: Three Ways to Monitor Your Code.

01:31 And if you’re ready to start testing your code, there’s a great walkthrough on Python’s built-in testing library: Python’s unittest, Writing Unit Tests for Your Code.

01:42 Thanks for tagging along. Let us know what your favorite part of the course was, and as always, happy Pythoning.

Become a Member to join the conversation.