Profiling and Memory Modules

cProfile

C-backed deterministic profiler for function call counts and timing statistics. Profile.runcall profiles a callable and returns its result. Analyze collected statistics using pstats; profiler timings include measurement overhead and are not a substitute for controlled benchmarking.

Formal Syntax & Structure

python syntaxpython
import cProfile

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
import cProfileprofiler = cProfile.Profile()print(profiler.runcall(sum, [2, 3]))
Python Reference