Performance Analysis
What is the problem with timing a very short operation once, and what is the fix?
- AShort operations take no time, so there is no need to measure
- BTiming short operations damages the CPU
- CThe operation is too short relative to clock resolution and timing overhead to measure accurately; repeat it many times, time the total and divide
Show answer and explanation
Answer: C. The operation is too short relative to clock resolution and timing overhead to measure accurately; repeat it many times, time the total and divide
Timing functions are limited by clock granularity (resolution) and by the time needed to call them. If the operation is comparable to or shorter than these, the result is mostly measurement error. Repeating it thousands or tens of thousands of times, timing the total and dividing gives an accurate per-call estimate. Repetition can change conditions, though, for example by keeping data cache-resident, unlike real usage.
- A. Even short operations add up when called often.
- B. The CPU is not damaged.
- C. Correct. It reduces the impact of measurement overhead.