The Python Profiler

This section describes the Python profiler—a tool that can be used to analyze the runtime performance of a program.

profile

The profile module is used to collect profiling information.

						run(command
						[,
						filename])
					

Executes the contents of command using the exec statement under the profiler. filename is the name of a file in which raw profiling data is saved. If omitted, a report such as the following is printed to standard output:

 126 function calls (6 primitive calls) in 5.130 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.030 0.030 5.070 5.070 <string>:1(?) 121/1 5.020 0.041 5.020 5.020 book.py:11(process) 1 0.020 0.020 5.040 5.040 book.py:5(?) 2 0.000 0.000 0.000 ...

Get Python Essential Reference, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.