Reference for learners¶
The reusable workflow¶
Reproduce the problem with the smallest representative input.
State the expected result and protect it with a test.
Choose a benchmark boundary and repeat the fixed useful work.
Profile broadly enough to locate a costly call path.
Narrow the investigation to functions, lines, memory, or system activity.
Form one hypothesis and make one focused change.
Rerun correctness checks, then the original benchmark.
Report evidence, variability, limitations, and the next decision.
Command map¶
Goal |
Terminal or Python |
IPython/Jupyter |
|---|---|---|
Debug interactively |
|
|
Time an application region |
|
|
Repeat a short benchmark |
|
|
Profile calls |
|
|
Read profile data |
|
|
Profile selected lines |
|
|
Visualize a call profile |
|
same, subject to site policy |
Profiler fields¶
call count (
ncalls): how often a function ran;internal time (
tottime): time in the body, excluding callees;cumulative time (
cumtime): time in the body and all descendants;hits: executions of a profiled line;
time per hit: measured line time divided by hits.
Profiler timings include profiler overhead. Use their ranking to decide where to investigate, then use a benchmark to compare the final variants.
Measurement checklist¶
What useful work and input are fixed?
How is correctness checked?
What begins and ends the timed region?
Were setup, I/O, compilation, or transfer costs included intentionally?
What machine, allocation, Python environment, and thread settings were used?
Were warm-up and repetitions appropriate for the run length?
Are raw observations retained, and which statistic summarizes them?
What uncertainty or limitation constrains the conclusion?
Diagnostic safety¶
Logs, tracebacks, ic() output, and profile artifacts can reveal tokens, file paths, user names, hostnames, arguments, or input-derived data. Prefer synthetic reproductions. Log metadata such as shape and range rather than complete data, inspect artifacts before sharing, and follow the site’s retention and transfer policy.
Glossary¶
Benchmark : A controlled measurement used to compare performance for fixed useful work.
Correctness oracle : A check that decides whether an observed result is acceptable.
Deterministic profiler : A profiler that records call events, usually with more perturbation than sampling.
Hot path : A frequently executed or costly path supported by measurement evidence.
Instrumentation overhead : Extra work introduced by observation itself.
Sampling profiler : A profiler that periodically observes execution rather than recording every event.
Further reading¶
Python:
pdb,logging,timeit, andcProfile/pstatsIceCream repository, for optional diagnostic printing