问题描述
我是PHP开发人员,我一直以为微型优化是不值得的。如果您真的需要额外的性能,您可以编写软件,使其架构更快,或者编写一个C ++扩展来处理慢速任务(或者更好的是,使用HipHop编译代码)。但是,今天一个工作对象告诉我,在
I am a PHP developer and I have always thought that micro-optimizations are not worth the time. If you really need that extra performance, you would either write your software so that it's architecturally faster, or you write a C++ extension to handle slow tasks (or better yet, compile the code using HipHop). However, today a work mate told me that there is a big difference in
is_array($array)
和
$array === (array) $array
我就像呃,这是一个毫无意义的比较真的 ,但他不会同意我的意见。他是我们公司最好的开发人员,负责每天大约有5000万SQL查询的网站。所以,我想知道这可能是错误的或微型优化真的值得的时间和时间?
and I was like "eh, that's a pointless comparison really", but he wouldn't agree with me.. and he is the best developer in our company and is taking charge of a website that does about 50 million SQL queries per day -- for instance. So, I am wondering here is that could he be wrong or micro-optimization really worth the time and when?
推荐答案
当您有证据表明您正在优化瓶颈时,优化是值得的。
Micro-optimisation is worth it when you have evidence that you're optimising a bottleneck.
通常不值得 - 写最可读的代码可以,并使用现实的基准来检查性能。如果您发现自己遇到瓶颈,那么微软可以优化这些代码(按照您的要求进行测量)。有时少量的微优化可能会产生巨大的差异。
Usually it's not worth it - write the most readable code you can, and use realistic benchmarks to check the performance. If and when you find you've got a bottleneck, micro-optimise just that bit of code (measuring as you go). Sometimes a small amount of micro-optimisation can make a huge difference.
但是,不要微型优化 >你的代码...最终会变得更难维护,你很可能会发现你已经错过了真正的瓶颈,或者你的微观优化是损害性能而不是帮助。
But don't micro-optimise all your code... it will end up being far harder to maintain, and you'll quite possibly find you've either missed the real bottleneck, or that your micro-optimisations are harming performance instead of helping.
这篇关于微观优化是否值得时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!