性能:大于/小于vs不等于 [英] Performance: greater / smaller than vs not equal to

查看:1744
本文介绍了性能:大于/小于vs不等于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道

之间的性能是否有差异检查值是否大于/小于

checking if a value is greater / smaller than another

for(int x = 0; x < y; x++); // for y > x

如果值不等于另一个

for(int x = 0; x != y; x++); // for y > x

为什么?

:如果我比较为零,如果比较为零,是否有进一步的差异?

In addition: What if I compare to zero, is there a further difference?

如果答案也考虑一个assebled视图的代码将是很好。

It would be nice if the answers also consider an assebled view on the code.

编辑:
由于大多数人指出性能的差异当然是可以忽略的,但我对cpu级别的差异感兴趣。哪个操作更复杂?

As most of you pointed out the difference in performance of course is negligible but I'm interested in the difference on the cpu level. Which operation is more complex?

对我来说,这是一个学习/理解技巧的问题。

To me it's more a question to learn / understand the technique.

我删除了 Java 标记,这是我不经意地添加的,因为问题通常不是基于Java,对不起。

I removed the Java tag, which I added accidentally because the question was meant generally not just based on Java, sorry.

推荐答案

你应该做更清楚,更安全和更容易理解的事情。这些微调讨论通常浪费你的时间,因为

You should still do what is clearer, safer and easier to understand. These micro-tuning discussions are usually a waste of your time because


  • 他们很少有可测量的差异

  • 当它们有所不同时,如果您使用不同的JVM或处理器,这可能会改变。

注意:生成的机器也可以改变处理器或JVM,所以看起来这在大多数情况下不是很有帮助即使你对汇编代码非常熟悉。

Note: the machine generated can also change with processor or JVM, so looking this is not very helpful in most cases, even if you are very familiar with assembly code.

更重要的是软件的可维护性。

What is much, much more important is the maintainability of the software.

这篇关于性能:大于/小于vs不等于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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