JIT编译器和内部循环

编程入门 行业动态 更新时间:2024-10-28 07:29:25
本文介绍了JIT编译器和内部循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

为什么JIT编译器不能使用以下代码?

Why is the JIT-compiler not working for the following code?

每个循环似乎都花费了很长时间

(请参阅我的其他有关执行时间的文章.简单循环的速度

(see my other post about executing time. Speed of simple loop

public static void main (String[] args) { for (int j = 0; j < 10; j++) { float f; long start = System.nanoTime(); for (int i = 0; i < 2000000000; i++) { f = i * 0.0001F; } long end = System.nanoTime(); long timeToCallNanoTime = System.nanoTime() - end; long time = Math.max(0, end - start - timeToCallNanoTime); System.out.println("time: " + time + " ns."); } }

结果:

time: 6639317628 ns. time: 6630196045 ns. time: 6632583856 ns. time: 6617596798 ns. time: 6605243858 ns. time: 6609097755 ns. time: 6627151876 ns. time: 6623427381 ns. time: 6632506712 ns. time: 6615870257 ns.

推荐答案

它对我有效,正如您在上一个问题的答案中所见.

It works for me in as you can see in my answer to your previous question.

您很有可能正在使用32位Windows附带的客户端JVM.客户端JVM并未对代码进行尽可能多的优化以最小化启动时间.我建议您使用默认情况下使用-server JVM的64位JVM,它将更加积极地优化代码.

Most likely you are using the client JVM which comes with 32-bit Windows. The client JVM doesn't optimise the code as much to minimise startup time. I suggest you use the 64-bit JVM which uses the -server JVM by default and it will optimise the code more aggressively.

顺便说一句,我正在使用Java 7 update40.如果您的Java版本真的很旧,它可能无法优化循环.

BTW I was using Java 7 update 40. If you have a really old version of Java, it might not optimise the loop away.

更多推荐

JIT编译器和内部循环

本文发布于:2023-11-07 09:15:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1566067.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:编译器   JIT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!