Profiling Conclusion
Last updated on 2024-03-28 | Edit this page
Estimated time: 5 minutes
Overview
Questions
- What has been learnt about profiling?
Objectives
- Review what has been learnt about profiling
This concludes the profiling portion of the course.
cProfile, snakeviz and
line_profiler have been introduced, these are some of the
most accessible Python profiling tools.
With these transferable skills, if necessary, you should be able to
follow documentation to use more advanced Python profiling tools such as
scalene.
What profiling is:
- The collection and analysis of metrics relating to the performance of a program during execution .
Why programmers can benefit from profiling:
- Narrows down the costly areas of code, allowing optimisation to be prioritised or decided to be unnecessary.
When to Profile:
- Profiling should be performed on functional code, either when concerned about performance or prior to release/deployment.
What to Profile:
- The collection of profiling metrics will often slow the execution of code, therefore the test-case should be narrow whilst remaining representative of a realistic run.
How to function-level profile:
- Execute
cProfileviapython -m cProfile -o <output file> <script name> <arguments> - Execute
snakevizviapython -m snakeviz <output file>
How to line-level profile:
- Import
profilefromline_profiling - Decorate targeted methods with
@profile - Execute
line_profilerviapython -m kernprof -lvr <script name> <arguments>