I want to do some timing tests on a Java application.
This is what I am currently doing:
long startTime = System.currentTimeMillis();
doSomething();
long finishTime = System.currentTimeMillis();
System.out.println("That took: "+(finishTime-startTime)+ " ms");
Is there anything "wrong" with performance testing like this? What is a better way?
Does anyone ever use stopwatch benchmarking, or should a
Code:
Don't spam : url removed
Performance Tuning tool always be used? Are there any good free tools available for Java? What tools do you use?
To clarify my concerns, stopwatch benchmarking is subject to error due to operating system scheduling. On a given run of your program the OS might schedule another process (or several) in the middle of the function you're timing. In Java things are even a little bit worse if you're trying to time a threaded application, as the JVM scheduler throws even a little bit more randomness into the mix.
How do you address operating system scheduling when benchmarking?