Python profile Module
Example
Measure how long a function takes (prints a profiling table):
import profile
def work():
s = 0
for i in range(20000):
s += i*i
return s
profile.run('work()')
Try it Yourself »
Definition and Usage
The profile module provides a pure-Python deterministic profiler.
Use it to measure how much time your functions spend running, and combine it with pstats
to sort and print results.
Members
Member | Description |
---|---|
Profile | Profiler class used to start/stop profiling and collect stats. |
run() | Run a string of code under the profiler (module-level function). |
runctx() | Like run() , but with explicit globals/locals (module-level function). |
Profile.runcall() | Call a function under the profiler. |