String formatTime(long nanotime) {
String ret = "";
DecimalFormat df = new DecimalFormat("#.###");
long time = nanotime;
ret = time > 1E3 ? df.format(time / 1E3) + "µs" : df.format(time) + " ns";
ret = time > 1E6 ? df.format(time / 1E6) + "ms" : ret;
ret = time > 1E9 ? df.format(time / 1E9) + "s" : ret;
ret = time > 60 * 1E9 ? df.format(time / (1E9 * 60)) + "min" : ret;
return ret;
}
Returns the string representation of the given time (nanoseconds) in the right format (s, ms, µs, min). You can use it for standard time formatting, and performance debugging.
Keine Kommentare:
Kommentar veröffentlichen