Last active
June 15, 2016 14:14
-
-
Save azakordonets/1c8f47cac4b7645cb5aaaa055d034e3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
long startTime = System.nanoTime(); | |
method(); | |
long stopTime = System.nanoTime(); | |
long millis = stopTime - startTime; | |
public String getDurationFormattedString(long startTime, long stopTime) { | |
final long nanosDifference = stopTime - startTime; | |
return String.format("%02d min, %02d sec %02d millis", | |
TimeUnit.NANOSECONDS.toMinutes(nanosDifference), | |
TimeUnit.NANOSECONDS.toSeconds(nanosDifference) - | |
TimeUnit.MINUTES.toSeconds(TimeUnit.NANOSECONDS.toMinutes(nanosDifference)), | |
TimeUnit.NANOSECONDS.toMillis(nanosDifference) | |
); | |
System.out.println(getDurationFormattedString(startTime, stopTime)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment