Performance Analysis
In a program processing large amounts of data, which improvement is most likely to give the largest speedup?
- AShortening variable names
- BReplacing an n² algorithm with an n log n one
- CDeleting comments
Show answer and explanation
Answer: B. Replacing an n² algorithm with an n log n one
With n = 1 million, n² is 1 trillion while n log n is about 20 million, a 50,000-fold difference. Compared with the few-fold gains from micro-optimization or hardware upgrades, algorithmic improvements can be worth orders of magnitude. Performance work should first check whether a high-complexity algorithm is in use, then layer on improvements such as better cache use and parallelization.
- A. Variable names do not affect execution speed.
- B. Correct. The gap grows by orders of magnitude with more data.
- C. Comments do not affect execution speed.