From 0c140072885301829d911645109273f42c20d79e Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Thu, 2 Jan 2025 05:25:00 +0800 Subject: [PATCH] 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 --- Row.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Row.c b/Row.c index a0148f81c..e3cfc6e11 100644 --- a/Row.c +++ b/Row.c @@ -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;