ref: 09d90658f13c87bcc4af03897731901843e57123
parent: eb7077ed7773e1a1f06db58f77c7d52c05452d61
author: Henrik Gramner <[email protected]>
date: Sat Feb 15 09:52:45 EST 2020
cli: Implement line buffering in print_stats() Console output is incredibly slow on Windows, which is aggravated by the lack of line buffering. As a result, a significant percentage of overall runtime is actually spent displaying the decoding progress. Doing the line buffering manually alleviates most of the issue.
--- a/tools/dav1d.c
+++ b/tools/dav1d.c
@@ -113,18 +113,24 @@
static void print_stats(const int istty, const unsigned n, const unsigned num,
const uint64_t elapsed, const double i_fps)
{
- if (istty) fputs("\r", stderr);
- const double d_fps = 1e9 * n / elapsed;
- const double speed = d_fps / i_fps;
- if (num == 0xFFFFFFFF) {
- fprintf(stderr, "Decoded %u frames", n);
- } else {
- fprintf(stderr, "Decoded %u/%u frames (%.1lf%%)", n, num,
- 100.0 * n / num);
+ char buf[80], *b = buf, *const end = buf + 80;
+
+ if (istty)
+ *b++ = '\r';
+ if (num == 0xFFFFFFFF)
+ b += snprintf(b, end - b, "Decoded %u frames", n);
+ else
+ b += snprintf(b, end - b, "Decoded %u/%u frames (%.1lf%%)",
+ n, num, 100.0 * n / num);
+ if (i_fps && b < end) {
+ const double d_fps = 1e9 * n / elapsed;
+ const double speed = d_fps / i_fps;
+ b += snprintf(b, end - b, " - %.2lf/%.2lf fps (%.2lfx)",
+ d_fps, i_fps, speed);
}
- if (i_fps)
- fprintf(stderr, " - %.2lf/%.2lf fps (%.2lfx)", d_fps, i_fps, speed);
- if (!istty) fputs("\n", stderr);
+ if (!istty)
+ strcpy(b > end - 2 ? end - 2 : b, "\n");
+ fputs(buf, stderr);
}
int main(const int argc, char *const *const argv) {