GUI 应用程序和测量运行时间 [英] GUI Application and measuring the running time

查看:31
本文介绍了GUI 应用程序和测量运行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(1) 我写了一个关于这个问题的问题,但我认为我没有正确说明问题,所以我删除了它.切入正题,在我的 GUI 应用程序中,我注意到当我想测量使用 System.currentTimeMillis(); 的方法所花费的时间时,与通过终端或控制台运行 jar 文件的标准方式,Java Swing 在这里有什么影响吗?

(1) I wrote a question about this issue but I think I did not state the problem correctly so I removed it. To get to the point, in my GUI application, I notice when I want to measure the running time taken by a method using System.currentTimeMillis();, the time becomes very short and unrealistic comparing with the standard way of running jar file via terminal or console, does Java Swing make some effects here?

(2) 因为我想保留我的 GUI 并解决这个问题,我读到了禁用 JIT 的可能性,我如何将它写为我的程序中的一段代码,以便在它运行时,JIT 在运行期间被禁用仅我的应用程序的运行时.

(2) Since I want to keep my GUI and also solve this issue, I read about the possibility of disabling JIT, how can I write it as a piece of code in my program so when it runs, JIT is disabled during the runtime of my application only.

谢谢.

推荐答案

使用 -Xint 选项,它在仅解释模式下运行应用程序.编译到本机代码被禁用,所有字节码由解释器.这种模式下不存在即时 (JIT) 编译器提供的性能优势."

Run your program using the -Xint option, which "Runs the application in interpreted-only mode. Compilation to native code is disabled, and all bytecode is executed by the interpreter. The performance benefits offered by the just in time (JIT) compiler are not present in this mode."

作为一个具体的例子,这个 AnimationTest 显示了 花费的平均时间PaintComponent() 使用 System.nanoTime().使用 -Xint 选项,时间保持相当稳定:

As a concrete example, this AnimationTest displays the average time spent in paintComponent() using System.nanoTime(). With the -Xint option, the time remains fairly constant:

java -Xint -cp build/classes overflow.AnimationTest

如果没有这个选项,即使用编译为本机代码,很容易看到绘制时间的长期减少,有时减少一个数量级:

Without the option, i.e. with compilation to native code, it's easy to see a secular decrease in paint time, sometimes by as much as an order of magnitude:

java -cp build/classes overflow.AnimationTest

这篇关于GUI 应用程序和测量运行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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