in Extremem/src/main/java/com/amazon/corretto/benchmark/extremem/RelativeTimeMetrics.java [1262:1351]
static String us2s (ExtrememThread t, long us) {
String result;
long quotient = 0;
if (us == 0) {
Util.ephemeralString(t, 3);
return new String("0us");
} else if (us < 0) {
us *= -1;
result = "-";
} else
result = "";
int sb_length = result.length();
int sb_capacity = Util.ephemeralStringBuilder(t, sb_length);
if (us > (3600 * 1000000L)) { // more than 1 hour
quotient = us / (3600 * 1000000L);
us = us % (3600 * 1000000L);
result += String.valueOf(quotient) + "h:";
int digits = Util.decimalDigits(quotient);
sb_capacity = Util.ephemeralStringBuilderAppend(t, sb_length,
sb_capacity, digits);
sb_length += digits;
sb_capacity = Util.ephemeralStringBuilderAppend(t, sb_length,
sb_capacity, 2);
sb_length += 2;
}
if (us > (60 * 1000000L)) { // more than 1 minute
quotient = us / (60 * 1000000L);
us = us % (60 * 1000000L);
result += String.valueOf(quotient) + "m:";
int digits = Util.decimalDigits(quotient);
sb_capacity = Util.ephemeralStringBuilderAppend(t, sb_length,
sb_capacity, digits);
sb_length += digits;
sb_capacity = Util.ephemeralStringBuilderAppend(t, sb_length,
sb_capacity, 2);
sb_length += 2;
}
if ((us == 0) || us > (1000000L)) { // more than 1 s
quotient = us / (1000000L);
us = us % (1000000L);
result += String.valueOf(quotient) + "s:";
int digits = Util.decimalDigits(quotient);
sb_capacity = Util.ephemeralStringBuilderAppend(t, sb_length,
sb_capacity, digits);
sb_length += digits;
sb_capacity = Util.ephemeralStringBuilderAppend(t, sb_length,
sb_capacity, 2);
sb_length += 2;
}
if (us > 1000L) { // more than 1 ms
quotient = us / 1000L;
us = us % 1000L;
result += String.valueOf(quotient) + "ms:";
int digits = Util.decimalDigits(quotient);
sb_capacity = Util.ephemeralStringBuilderAppend(t, sb_length,
sb_capacity, digits);
sb_length += digits;
sb_capacity = Util.ephemeralStringBuilderAppend(t, sb_length,
sb_capacity, 2);
sb_length += 2;
}
if (us > 0) {
result += String.valueOf(us) + "us:";
int digits = Util.decimalDigits(us);
sb_capacity = Util.ephemeralStringBuilderAppend(t, sb_length,
sb_capacity, digits);
sb_length += digits;
sb_capacity = Util.ephemeralStringBuilderAppend(t, sb_length,
sb_capacity, 2);
sb_length += 2;
}
// Assume compiler optimizes this (so there's not a String
// followed by a substring operation).
Util.ephemeralStringBuilderToString(t, sb_length - 1, sb_capacity);
return result.substring(0, result.length() - 1);
}