Performance Analysis
A function f that finishes in 20 ns per call is called millions of times. It is measured with an instrumentation profiler that inserts recording code at the entry and exit of functions. If the recording takes 60 ns in total per call and all of that time is counted as time in f, how many times its true time does the measured time of f become?
- A3 times
- B4 times
- CUnchanged (1 time)
Show answer and explanation
Answer: B. 4 times
Each measured call of f takes the true 20 ns plus 60 ns of recording, or 80 ns, and 80 ÷ 20 = 4 times. This phenomenon, in which the mechanism for measuring changes the very behavior being measured, is called the probe effect. Recording also replaces cache contents, so in practice the slowdown can be even larger. For programs with many small functions, measure the time breakdown with a sampling profiler, or subtract the measurement overhead itself.
- A. This confuses the answer with the 60 ns of recording divided by the true 20 ns (60 ÷ 20 = 3).
- B. Correct. (20 + 60) ÷ 20 = 4 times.
- C. Recording also takes time, so the measured time becomes longer.