0

The response time of a Java program reduces after it is repeated many times. What is the reason for it? Is the following explanation correct?:

The total execution time includes code generation time + garbage collect time + execution time. After the same program is repeated many times, the code generation time does not appear as a factor.

Can you recommend some references on it to me? Thanks.

ArjunShankar
  • 23,020
  • 5
  • 61
  • 83
susanna
  • 1,395
  • 3
  • 20
  • 32
  • 1
    Looks like you already have your answer... – talnicolas Apr 17 '12 at 15:43
  • Where did you get your explanation? – Rory Hunter Apr 17 '12 at 15:43
  • http://stackoverflow.com/questions/504103/how-do-i-write-a-correct-micro-benchmark-in-java is about performance testing and mentions these issues + JIT warmup etc. – assylias Apr 17 '12 at 15:44
  • I did a search on the Internet. But I want to verify it and see whether it is accurate. Another question is how many time should the program be repeated? – susanna Apr 17 '12 at 15:45
  • The biggest factor is the way that Java code is compiled, and the ability for the compiler to optimise the code when it's run repeatedly. Plenty of information on that to be found using your favourite search engine. – Anthony Grist Apr 17 '12 at 15:47
  • Look up "just in time compiler". – Hot Licks Apr 17 '12 at 15:51
  • 1
    Although, keep in mind that this behaviour is technically an _implementation detail_ of modern JVMs, and cannot be relied upon to exist in all cases. – Clockwork-Muse Apr 17 '12 at 16:03

1 Answers1

0

Another question is how many time should the program be repeated?

On the HotSpot / OpenJDK the default is 10,000 times see the -XX:CompileThreshold= option

http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130