summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorExplorer09 <explorer09@gmail.com>2024-04-03 00:16:04 +0800
committercgzones <cgzones@googlemail.com>2024-04-05 19:27:59 +0200
commitae932b4fa980acb8c80946d098c79e2ab3611d3f (patch)
treef871cad5895aeee32b7f7d0e30a1e9bcc535ae06
parent24b1513296fd61722166625ad46be1c56a5efc44 (diff)
New Row_printNanoseconds() function
It prints the time in one of these formats: nanoseconds, "fraction of seconds", "minutes + seconds + milliseconds". If the total time is greater than 10 minutes, it uses Row_printTime() to print higher time units. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
-rw-r--r--Row.c51
-rw-r--r--Row.h3
2 files changed, 54 insertions, 0 deletions
diff --git a/Row.c b/Row.c
index a175c9e3..66a4aa07 100644
--- a/Row.c
+++ b/Row.c
@@ -403,6 +403,57 @@ void Row_printTime(RichString* str, unsigned long long totalHundredths, bool col
}
}
+void Row_printNanoseconds(RichString* str, unsigned long long totalNanoseconds, bool coloring) {
+ if (totalNanoseconds == 0) {
+ int shadowColor = coloring ? CRT_colors[PROCESS_SHADOW] : CRT_colors[PROCESS];
+
+ RichString_appendAscii(str, shadowColor, " 0ns ");
+ return;
+ }
+
+ char buffer[10];
+ int len;
+ int baseColor = CRT_colors[PROCESS];
+
+ if (totalNanoseconds < 1000000) {
+ len = xSnprintf(buffer, sizeof(buffer), "%6luns ", (unsigned long)totalNanoseconds);
+ RichString_appendnAscii(str, baseColor, buffer, len);
+ return;
+ }
+
+ unsigned long long totalMicroseconds = totalNanoseconds / 1000;
+ if (totalMicroseconds < 1000000) {
+ len = xSnprintf(buffer, sizeof(buffer), ".%06lus ", (unsigned long)totalMicroseconds);
+ RichString_appendnAscii(str, baseColor, buffer, len);
+ }
+
+ unsigned long long totalSeconds = totalMicroseconds / 1000000;
+ unsigned long microseconds = totalMicroseconds % 1000000;
+ if (totalSeconds < 60) {
+ int width = 5;
+ unsigned long fraction = microseconds;
+ if (totalSeconds >= 10) {
+ width--;
+ fraction /= 10;
+ }
+ len = xSnprintf(buffer, sizeof(buffer), "%u.%0*lus ", (unsigned int)totalSeconds, width, fraction);
+ RichString_appendnAscii(str, baseColor, buffer, len);
+ return;
+ }
+
+ if (totalSeconds < 600) {
+ unsigned int minutes = totalSeconds / 60;
+ unsigned int seconds = totalSeconds % 60;
+ unsigned int milliseconds = microseconds / 1000;
+ len = xSnprintf(buffer, sizeof(buffer), "%u:%02u.%03u ", minutes, seconds, milliseconds);
+ RichString_appendnAscii(str, baseColor, buffer, len);
+ return;
+ }
+
+ unsigned long long totalHundredths = totalMicroseconds / 1000 / 10;
+ Row_printTime(str, totalHundredths, coloring);
+}
+
void Row_printRate(RichString* str, double rate, bool coloring) {
char buffer[16];
diff --git a/Row.h b/Row.h
index f67c6103..6d882909 100644
--- a/Row.h
+++ b/Row.h
@@ -154,6 +154,9 @@ void Row_printCount(RichString* str, unsigned long long number, bool coloring);
/* Takes time in hundredths of a seconds. Prints 9 columns. */
void Row_printTime(RichString* str, unsigned long long totalHundredths, bool coloring);
+/* Takes time in nanoseconds. Prints 9 columns. */
+void Row_printNanoseconds(RichString* str, unsigned long long totalNanoseconds, bool coloring);
+
/* Takes rate in bare unit (base 1024) per second. Prints 12 columns. */
void Row_printRate(RichString* str, double rate, bool coloring);

© 2014-2024 Faster IT GmbH | imprint | privacy policy