How do you decide between optimising code and keeping it simple?
C++ attracts premature optimisation, so interviewers are checking for discipline.
The default is clarity. Write the straightforward version, measure, and optimise only what the profiler identifies. The reason is not that performance does not matter — it is that intuition about C++ performance is unreliable. Cache behaviour, branch prediction, and compiler optimisation regularly make the "obviously faster" code slower.
When to optimise up front:
- Choice of data structure and algorithm. This is not premature — it is design. Getting the complexity class wrong is expensive to fix later.
- Memory layout on a hot path. Contiguous storage and struct-of-arrays versus array-of-structs are architectural decisions.
- Anything in a documented hard real-time budget.
How to keep it honest: benchmark with realistic data, use a proper harness such as Google Benchmark rather than timing one run, and check the generated assembly when a result surprises you.
Note: A strong story is one where you optimised something, measured no improvement, and reverted it. That is a habit interviewers rarely hear about and always respect.





