Easiest way to calculate elapsed time in Java

Quite often in our day-to-day programming, we need to compute how long a specific portion of the code takes to complete. For e.g; you might want to check how long a method takes to complete.  In Java, the simplest way to accomplish this is to use System.nanoTime() method. The following example shows how you can […]