Subject:
Java JIT
From:
Isaac Gouy
Date:
20.6.2012 г. 03:47 ч.
To:
Ivan Zahariev

Hi Ivan


> My expectations was that the interpretation/compilation time of the program 
> will be a negligible part of the 10x execution.

That's correct - but it isn't correct to assume that a method that has been fully optimized can immediately be used by the JVM. In ordinary Java programs that isn't a problem, but in tiny programs that only have a main method calling one other method there might be no opportunity to replace the initial instructions with the fully optimized instructions.

http://www.oracle.com/technetwork/java/hotspotfaq-138619.html#benchmarking_simple



> Last questions -- Can I force Java to run only compiled code? Can I save 
> the compiled code and execute it pretty much as I execute a compiled C++ 
> binary?

Yes, using tools like Excelsior JET - but that really isn't how most Java programs are used, and really isn't what's slowing down your Java program.


Here are times for the SimplePrimes.java program that uses int[]

java SimplePrimes
real    0m3.156s 
user    0m4.388s 
sys    0m0.204s

java -Xms500m SimplePrimes
real    0m2.331s
user    0m2.292s
sys    0m0.092s


Here are times for the SimplePrimes.java program that uses ArrayList<Integer>

java PrimeNumbersBenchmarkApp
real    0m8.978s
user    0m18.453s
sys    0m0.432s

java -Xms500m PrimeNumbersBenchmarkApp
real    0m5.100s
user    0m7.764s
sys    0m0.380s


Here are times for your primes.py program that does not append to a dynamic array (not the same as your Java program)
real    0m25.942s
user    0m25.594s
sys    0m0.296s

Here are times for the slowerprimes.py program that does append to a dynamic array (same as your Java program)
real    0m33.369s
user    0m32.954s
sys    0m0.368s


1) Your Python and PHP programs both use a special function instead of appending to a dynamic array -- they'll both be much slower when they are made to do the same as the other programs.

2) Both Java programs will be much faster when they are run with an appropriate initial heap size.


best wishes, Isaac