3 ms·
A fun read on word count optimization can be found in Abrash's Black Book: https://www.jagregory.com/abrash-black-book/#lessons-learned-in-the-pursuit-of-the-u
by shric 2y ago
A fun read on word count optimization can be found in Abrash's Black Book:
https://www.jagregory.com/abrash-black-book/#lessons-learned-in-the-pursuit-of-the-ultimate-word-counter https://www.jagregory.com/abrash-black-book/#lessons-learned...
You can gloss over the asm if you wish, the tricks that are explained around it are worth it imho.
- Joker_vD 2y agoI wonder if large lookup tables/table-driven state machines are still as good as they used to be. After all, even with all the on-chip caches, the additional memory accesses today seem to be slower than doing some multi-instruction SIMD voodoo.
- LegionMammal978 2y agoAt least the GNU version of wc [0] uses AVX2 for line counting, if available. Though it falls back to a simple character-by-character loop if you ask for a character count [not to be confused with a byte count!] or a word count. [0] https://git.savannah.gnu.org/cgit/coreutils.git/tree/src/wc_avx2.c?h=v9.5 https://git.savannah.gnu.org/cgit/coreutils.git/tree/src/wc_...