Performance Analysis

In a program processing large amounts of data, which improvement is most likely to give the largest speedup?

  1. AShortening variable names
  2. BReplacing an n² algorithm with an n log n one
  3. 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.
Practice this topic Back to topic

More Performance Analysis questions

  1. In software development, what is the purpose of automatically running benchmarks and recording results on every change?
  2. Benchmarks on a laptop vary widely between runs of the same program. Which pairs a CPU-side cause with a countermeasure correctly?
  3. When measuring performance on multicore or NUMA systems, why are threads sometimes pinned to specific cores (setting affinity)?
  4. When analyzing the performance of a GPU program, what is the most appropriate thing to check first?
  5. When choosing servers for a data center, which is NOT a consideration beyond peak performance?