优化代码 [英] Optimizing Code

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

问题描述

为您提供了用您喜欢的语言编写的大量代码,这些代码结合起来构成一个相当复杂的应用程序.它运行得很慢,您的老板要求您对其进行优化. 您需要采取哪些步骤来最有效地优化代码?

You are given a heap of code in your favorite language which combines to form a rather complicated application. It runs rather slowly, and your boss has asked you to optimize it. What are the steps you follow to most efficiently optimize the code?

您发现优化代码时哪些策略不成功?

What strategies have you found to be unsuccessful when optimizing code?

重写:您决定什么时候停止优化并说:这与不进行完全重写一样快."无论如何,您会主张进行简单的完全重写吗?您将如何设计它?

Re-writes: At what point do you decide to stop optimizing and say "This is as fast as it'll get without a complete re-write." In what cases would you advocate a simple complete re-write anyway? How would you go about designing it?

推荐答案

配置文件,然后尝试进行任何优化.

Profile before attempting any optimisation.

十分之九的时间不会浪费在您可能会猜到的地方.

9 times out of 10, the time won't be consumed where you might guess it is.

通常不成功的策略是微优化,而实际需要的是合适的算法.

The usual unsuccessful strategy is micro-optimisation, when what is actually required is the appropriate algorithm.

必填的Donald Knuth语录:

Obligatory Donald Knuth quote:

我们应该忘记效率低下的问题,大约有97%的时间是这样:过早的优化是万恶之源"

这篇关于优化代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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