Anything to measure Java compile time?

K.I.L.E.R

Retarded moron
Veteran
I assume if I make a program and it compiles in 15 seconds it's great.

If I change some code around and it compiles in 12 seconds I have optimised my code.

In conclusion this will lead to a more optimal program.

True or False?

PS: Link me up with a tool to get compile times. :)
 
FALSE. Compile time does not indicate runtime performance. It's possible that if you change things around so they lend themselves better to the optimizer it may actually take longer to compile. The opposite is true as well; you can change things around that readily rejects certain optimizations from happening so compile time shortens.
 
Thanks.

How can I test runtime performance?

I know how to optimise some things but I really can't see a difference during runtime. I want to see practical results with my optimisations.
 
You can learn to use the built-in profiler HPROF [http://developer.java.sun.com/developer/TechTips/2000/tt0124.html#tip2 -- 2nd tip on the page], use a professional tool such as JProbe, or do the timings yourself. I use a mix of self-timings and JProbe.

One thing to note, you need to ensure your code is called enough times to trip the HotSpot JVM before you start your timings. Generally you need to run your code in a loop (~100) then do your begin timestamp, code in a loop (significant high enough loop count to measure in seconds), then take your end timestamp. If using a profiler tool, you can discard the code taking the timestamps.

Code:
final int HOTSPOT_PRIMER = 100;
final int PERFORMANCE_LOOP = 10000;

for(int idx=HOTSPOT_PRIMER; --idx >= 0; ) {
    doCodeOfInterest();
}
final long beginTime = System.currentTimeMillis();
for(int idx=PERFORMANCE_LOOP; --idx >= 0; ) {
    doCodeOfInterest();
}
final long endTime = System.currentTimeMillis();
System.out.println("Time to execute " + PERFORMANCE_LOOP + " = " + (endTime - beginTime));

Some additional useful links:
http://www.javaperformancetuning.com/index.shtml
http://developer.java.sun.com/developer/technicalArticles/GUI/perfanal/
http://java.sun.com/products/hotspot/
[and some older but still somewhat useful sites:]
http://www.javaworld.com/javaworld/jw-04-1997/jw-04-optimize_p.html
http://www-2.cs.cmu.edu/~jch/java/optimization.html

This should be enough to get you started on your way...
 
Back
Top