Profiling in Python

Lot of information is available in the Python documentation website: . However, here is a small snapshot of how to use it :

Let us say you have a function call test(). First you need to run it:

import cProfile'from your_module import test; test()', 'prof')

It will save profiling results in ‘prof’, which can then be parsed with pstats module:

import pstats
p = pstats.Stats('fooprof')

You can then introspect the data. For instance the following code sort the results by time and print the 10 largest one.

Please follow and like us:
This entry was posted in Python and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published.