尽早计划效率与过早优化 [英] Planning for efficiency early vs Premature optimization

查看:65
本文介绍了尽早计划效率与过早优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎注意到在优化方面出现了两种思想流派:

I seem to notice two schools of thought emerging in regards to optimization:

  1. 过早的优化是万恶之源.仅当您编写了最易读和最简单的内容时,才应进行优化.如果在分析后确定软件太慢,则应进行优化.
  2. 优化应该在项目生命周期的早期完成.优化需要进行计划,但应该合理进行.
  1. Premature optimization is the root of all evil. You should only optimize when you've written the most readable and simplest thing possible. If after profiling you determine that the software is too slow, you should optimize.
  2. Optimizations should be done early in a project's lifecycle. Optimizations need to be planned for, but should be done reasonably.

从表面上看,它们似乎是截然相反的观点.问题是,我看到了两种思想流派的优点.我还可以想想这两种思维方式都帮助我编写了更好,更快的软件的时代.

On the face of things, they seem to be fairly opposed viewpoints. The thing is, I see the merit in both schools of thought. I can also think of times when both of these ways of thinking have helped me write better and faster software.

有没有办法调和这两个想法?有中间立场吗?有没有一个想法是完成工作的最佳工具?还是我提出了错误的二分法,两种观点可以和平共处?

Is there any way to reconcile these two ideas? Is there a middle ground? Is there a time when one idea is the best tool for the job? Or am I presenting a false dichotomy and both views can co-exist peacefully?

推荐答案

我通常要做的是应用那些不会花我任何钱(或几乎没有花钱)的优化方法.我也一直在寻找那些扩展性不好并且经常被调用的算法.除此之外,在软件运行之前,我不会进行优化,并且有机会启动分析器.只有到那时,我才会投入大量时间进行优化.

What I usually do is to apply those optimzations that don't cost me anything (or almost nothing). I also stay on the lookout for algorithms that don't scale well and are called very often. Other than that, I do not optimize until the software runs and I get a chance to fire up the profiler. Only then I will invest some serious time into optimization.

这篇关于尽早计划效率与过早优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆