Java >> 之间是否有任何性能差异和>>右移运算符?

发布于 2024-08-26 08:26:56 字数 179 浏览 3 评论 0原文

是否有理由认为>> (签名)和>> 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魔法唧唧 2024-09-02 08:26:57

不。
您的编译器会将这些转换为字节码,而 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文