System.nanoTime() and measurements

I'm still using simple System.currentTimeMillis() when need to test performance of some part of code. It's fast and easy to use, especially to profile some algorithm while coding; performance still is an important measure used to choose between few algorithms or choose the best way how to implement algorithm.
But for some algorithms, especially in development environment System.currentTimeMillis() doesn't give any valuable results as it's hard to choose between 0ms and 0ms returned for both algorithms :) System.nanoTime() can used in such situations. It helps to get precise measurement of code execution time.
But, everyone will say that it is not important what way of implementation you'll choose if difference is less than 1ms. It doesn't matter. And they will be right. In this case it doesn't matter what is faster, even if production amount of data is much more than testing amount of data and this may affect execution time significantly. Algorithm does matter.

It always depends on algorithm!

No comments: