Java >> 之间是否有任何性能差异和>>右移运算符?
是否有理由认为>> (签名)和>> Java 中的(无符号)右位移运算符会执行不同的操作吗?我在我的机器上无法检测到任何差异。
这纯粹是一个学术问题;我确信它永远不会成为瓶颈。我知道:最好首先写下你的意思;使用>>例如,除以 2。
我认为这取决于哪些架构将哪些操作实现为指令。
Is there ever reason to think the >> (signed) and >>> (unsigned) right bit-shift operators in Java would perform differently? I can't detect any difference on my machine.
This is purely an academic question; it's never going to be the bottleneck I'm sure. I know: it's best to write what you mean foremost; use >> for division by 2, for example.
I assume it comes down to which architectures have which operations implemented as an instruction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不。
您的编译器会将这些转换为字节码,而 JVM 将为您的架构解释字节码。我认为可以安全地假设您的架构具有一个指令集,其中包括在几个时钟周期内完成的两个操作。
无论如何,这些运算符的行为存在差异,因此您不能简单地互换它们。
No.
Your compiler will translate these to bytecode and the JVM will interpret the bytecode for your architecture. I think it is safe to assume that your architecture has an instruction set which includes both operations be done in few clock cycles.
Anyway, there is a difference in the behavior of these operators, so it isn't like you can just interchange them.