Skip to content

Commit 32fc21c

Browse files
committed
Add a new printing format to Row_printNanoseconds()
Add a new format: "1.0000ms" - "9.9999ms". Previously they would print as ".001000s" and ".009999s", and this new format adds one extra digit of precision. Note that I print the unit as "ms" rather than microseconds; this saves code for deciding whether to print the Greek "mu" or the Latin "u". Row_printNanoseconds() now prints this list of formats: " 0ns", "999999ns", "1.0000ms", "9.9999ms", ".010000s", ".999999s", "1.00000s", "59.9999s", "1:00.000", "9:59.999", "10:00.00" ... Signed-off-by: Kang-Che Sung <[email protected]>
1 parent 0862dc9 commit 32fc21c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Row.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,18 @@ void Row_printNanoseconds(RichString* str, unsigned long long totalNanoseconds,
418418
return;
419419
}
420420

421+
if (totalNanoseconds < 10000000) {
422+
// The precision is 0.1 microseconds here.
423+
// We print the unit in "ms" rather than microseconds in order
424+
// to save the code of choosing the Greek "mu" or Latin "u".
425+
uint32_t fraction = (uint32_t)totalNanoseconds / 100;
426+
unsigned int milliseconds = (unsigned int)(fraction / 10000);
427+
fraction %= 10000;
428+
len = xSnprintf(buffer, sizeof(buffer), "%u.%04ums ", milliseconds, (unsigned int)fraction);
429+
RichString_appendnAscii(str, baseColor, buffer, len);
430+
return;
431+
}
432+
421433
unsigned long long totalMicroseconds = totalNanoseconds / 1000;
422434
unsigned long long totalSeconds = totalMicroseconds / 1000000;
423435
uint32_t microseconds = totalMicroseconds % 1000000;

0 commit comments

Comments
 (0)