Jacki
Jacki

Reputation: 95

GUI Application and measuring the running time

(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) 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.

Thank you.

Upvotes: 1

Views: 397

Answers (1)

trashgod
trashgod

Reputation: 205865

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."

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

Upvotes: 2

Related Questions