# Profiling

> Finding the parts of a program that take the most time.

**Field:** Software Development  
**Category:** Compilers & Runtimes  
**Also known as:** Profiler, Code Profiling, Performance Profiling

## Think of it like

Think of it like a stopwatch on each runner in a race. You see who slows the team down.

## Definition

Profiling is measuring where a program spends its time or memory while it runs. A tool called a profiler watches the program and counts how long each function takes. The report shows which parts are slow and which barely matter. Often one small part takes most of the time. Profiling first means you fix the real slow spot instead of guessing.

## Example

Lucy's page takes 6 seconds to load. The profiler shows one function that resizes images takes 5 of them. She fixes just that one.

## Example code

```console
$ python3 -m cProfile -s cumtime slow.py
   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.500    0.500 slow.py:2(load)
        1    0.000    0.000    0.100    0.100 slow.py:4(draw)
```

The profiler shows load takes half a second, five times longer than draw.

## Why it matters

People are bad at guessing what is slow. A profile shows the truth in a few minutes.

## Common mistake

Speeding up code before measuring it. Hours go into parts that were never the problem.

## Three principles

- **Measure first.** Then change the code.
- **Time and memory.** Per function.
- **Find the big one.** One part often costs most.

## Related terms

- [Benchmark](https://learn.benibix.com/term/development/benchmark)
- [Cache](https://learn.benibix.com/term/development/cache)
- [Debugging](https://learn.benibix.com/term/development/debugging)
- [Function](https://learn.benibix.com/term/development/function)

## Told apart from

- [Profiling vs Benchmark](https://learn.benibix.com/compare/profiling-vs-benchmark): People think a benchmark tells you what to fix, and it does not. A profiler watches a whole program run and shows where the time goes. A benchmark times one piece of code many times, so you can compare two versions. Profile first to find the slow part. Then benchmark the old and new versions of that part.

---

Source: https://learn.benibix.com/term/development/profiling
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
