diff options
author | Rob Landley <rob@landley.net> | 2020-12-15 04:53:04 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2020-12-15 04:53:04 -0600 |
commit | 83326334d5bda7fefbd174630c23eae3b5f41604 (patch) | |
tree | 8d2e14e291683f139cc6b2b7c6ff20c73d783686 /toys | |
parent | b25f04996cfd4700fd3ee164168d9737c010908c (diff) | |
download | toybox-83326334d5bda7fefbd174630c23eae3b5f41604.tar.gz |
Speed up count: use 64k block size, update display at most 4x/second.
Diffstat (limited to 'toys')
-rw-r--r-- | toys/other/count.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/toys/other/count.c b/toys/other/count.c index f3b6f821..3d388e78 100644 --- a/toys/other/count.c +++ b/toys/other/count.c @@ -17,16 +17,22 @@ config COUNT void count_main(void) { - uint64_t size = 0; + struct pollfd pfd = {0, POLLIN, 0}; + unsigned long long size = 0, last = 0, then = 0, now; + char *buf = xmalloc(65536); int len; - char buf[32]; + // poll, print if data not ready, update 4x/second otherwise for (;;) { - len = xread(0, toybuf, sizeof(toybuf)); + if (!(len = poll(&pfd, 1, (last != size) ? 250 : 0))) continue; + if (len<0 && errno != EINTR && errno != ENOMEM) perror_exit(0); + if ((len = xread(0, buf, 65536))) { + xwrite(1, buf, len); + size += len; + if ((now = millitime())-then<250) continue; + } + dprintf(2, "%llu bytes\r", size); if (!len) break; - size += len; - xwrite(1, toybuf, len); - xwrite(2, buf, sprintf(buf, "%"PRIu64" bytes\r", size)); } - xwrite(2, "\n", 1); + dprintf(2, "\n"); } |