Unsafe Engineering · 18 min · free with an account

Benchmark & Profile

Lesson preview · about 30%

Find the real bottleneck before optimizing.

Core idea

A benchmark measures a stable workload; a profiler explains where its time or allocations go.

Start with the idea

A benchmark measures a stable workload; a profiler explains where its time or allocations go. Change one variable, protect against optimized-away work, and compare distributions rather than one lucky run.

A benchmark asks how a specific workload behaves under controlled conditions. A profiler asks where time, allocations, or waits occur during that workload. Start with a question that matters to a user, such as median parse latency for a typical file or worst-case response time for a large project. Use a release build, warm up when appropriate, and keep input, hardware, and environment stable between comparisons. One Instant measurement is useful for a quick observation but too noisy to settle a small optimization.

Keep learning, for free

The rest of this lesson is waiting for you.

Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.

No payment details. Your account opens the complete Academy.

← All lessons in Macros & Systems Rust