[Toybox] [PATCH] seq: fast path for integers.

enh enh at google.com
Fri Dec 11 11:26:31 PST 2020


The question "why do we have setlinebuf(stdout)?" came up on the list
recently, and by strange coincidence here it is causing more trouble:
performance rather than usability this time. Just removing the line
buffering alone results in a significant speedup.

The switch to use %lld rather than %f in obvious cases is another major
speedup.

Calling strlen() once on TT.s and using fwrite() rather than using
printf() every time wouldn't be noticeable if the other two issues
weren't fixed, but is a decent chunk of the remaining time at this point.

GNU seq is still *another* 10x faster on my desktop, and I did experiment
with inlining the trivial `n /= 10` integer-to-ascii algorithm (to at
least remove some of the remaining printf() overhead) but the savings from
that were quite small at this point and didn't seem worth the extra
code. And while being 100x worse was a human-noticeable thing, being
10x worse than "basically instant even on very large inputs" doesn't
seem likely to be something anyone will notice (and we can worry about
that if/when they do).
---
 main.c         |  1 -
 tests/seq.test |  2 ++
 toys/lsb/seq.c | 21 ++++++++++++++++-----
 3 files changed, 18 insertions(+), 6 deletions(-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20201211/3adc8d7b/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-seq-fast-path-for-integers.patch
Type: text/x-patch
Size: 3808 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20201211/3adc8d7b/attachment-0002.bin>


More information about the Toybox mailing list