Premature optimization and Premature pessimization related to C++ coding standards

前端 未结 5 1796
夕颜
夕颜 2021-01-12 04:12

Herb Sutter\'s C++ coding standards says to avoid Premature optimization and Premature pessimization. But I feel both is doing the same th

5条回答
  •  我在风中等你
    2021-01-12 04:41

    What Herb means is that when you are faced with two equally readable options, always choose the most efficient one.

    Using std::vector::reserve() or the best standard container or algorithm is not premature optimization. However, not using them would be premature pessimisation.

    Premature optimization is when you sacrifice readability for the sake of some "optimization" that might even not be worth it. Use a profiler for that.

提交回复
热议问题