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

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

问题描述

我似乎注意到有关优化的两种思想流派:

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天全站免登陆