When is optimisation premature?

前端 未结 20 1240
悲哀的现实
悲哀的现实 2020-11-21 23:26

As Knuth said,

We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.

20条回答
  •  無奈伤痛
    2020-11-22 00:23

    The need to use a profiler should be left for extreme cases. The engineers of the project should be aware of where performance bottlenecks are.

    I think "premature optimisation" is incredibly subjective.

    If I am writing some code and I know that I should be using a Hashtable then I will do that. I won't implement it in some flawed way and then wait for the bug report to arrive a month or a year later when somebody is having a problem with it.

    Redesign is more costly than optimising a design in obvious ways from the start.

    Obviously some small things will be missed the first time around but these are rarely key design decisions.

    Therefore: NOT optimising a design is IMO a code smell in and of itself.

提交回复
热议问题