]> git.ipfire.org Git - thirdparty/coreutils.git/commit
uniq: avoid locking standard output when printing line counts with -c
authorCollin Funk <collin.funk1@gmail.com>
Fri, 26 Jun 2026 03:12:28 +0000 (20:12 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Mon, 29 Jun 2026 02:44:00 +0000 (19:44 -0700)
commit52ff9b97fbf6910dc6f04ad1fdb2d1851feb417b
treea6d28351e791db1361acf2e541e1f6c912a467f4
parentd7622d8629434b8d5d5064e9abca5b6f3dca9eda
uniq: avoid locking standard output when printing line counts with -c

This increases throughput on systems with unlocked stdio functions.
E.g., 2.5x in the following case:

    $ timeout 1m taskset 1 shuf -r -i 0-100 \
        | taskset 2 uniq -c \
        | taskset 3 pv -r > /dev/null
    [ 100MiB/s]
    $ timeout 1m taskset 1 shuf -r -i 0-100 \
        | taskset 2 uniq -c \
        | taskset 3 pv -r > /dev/null
    [ 246MiB/s]

* src/uniq.c: Include assure.h.
(writeline): Convert the value to a string by hand and use fwrite, which
may be unlocked, instead of printf.
* tests/uniq/uniq-c-width.sh: New test to verify the padding logic.
* tests/local.mk (all_tests): Add the test case.
* NEWS: Mention the improvement.
NEWS
src/uniq.c
tests/local.mk
tests/uniq/uniq-c-width.sh [new file with mode: 0755]