Call me old-fashioned, but this is the easiest approach, in my opinion:
long a, b, c, d; a = System.currentTimeMillis(); // some code 1 b = System.currentTimeMillis(); // some code 2 c = System.currentTimeMillis(); // some code 3 d = System.currentTimeMillis(); System.out.println("Some code 1 took "+(ba)+"mil to execute. ("+((ba)/1000)+" seconds)"); System.out.println("Some code 2 took "+(cb)+"mil to execute. ("+((cb)/1000)+" seconds)"); System.out.println("Some code 3 took "+(dc)+"mil to execute. ("+((dc)/1000)+" seconds)");
Hope this helps :)
source share