Skip to content

Commit

Permalink
Add a new printing format to Row_printNanoseconds()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Explorer09 committed Jan 2, 2025
1 parent c7b6e4b commit 46e88a9
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Row.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,18 @@ void Row_printNanoseconds(RichString* str, unsigned long long totalNanoseconds,
return;
}

if (totalNanoseconds < 10000000) {
// The precision is 0.1 microseconds here.
// We print the unit in "ms" rather than microseconds in order
// to save the code of choosing the Greek "mu" or Latin "u".
uint32_t fraction = (uint32_t)totalNanoseconds / 100;
unsigned int milliseconds = (unsigned int)(fraction / 10000);
fraction %= 10000;
len = xSnprintf(buffer, sizeof(buffer), "%u.%04ums ", milliseconds, (unsigned int)fraction);
RichString_appendnAscii(str, baseColor, buffer, len);
return;
}

unsigned long long totalMicroseconds = totalNanoseconds / 1000;
unsigned long long totalSeconds = totalMicroseconds / 1000000;
unsigned long microseconds = totalMicroseconds % 1000000;
Expand Down

0 comments on commit 46e88a9

Please sign in to comment.