]> git.ipfire.org Git - thirdparty/coreutils.git/commit
shuf: prefer fwrite over fputs and fputc
authorCollin Funk <collin.funk1@gmail.com>
Thu, 7 May 2026 03:39:20 +0000 (20:39 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Fri, 8 May 2026 06:32:52 +0000 (23:32 -0700)
commitebe2b7513e36fc3be99c9c57b0bc2c136e387fae
treeb135ca6f7d9c584464a8d69e09fe432734a7cbe4
parentcab1d4bfbd0fa9e970e68e70d4b1453e6225f6e4
shuf: prefer fwrite over fputs and fputc

On an AMD Ryzen 7 3700X running GNU/Linux:

    $ timeout 30 taskset 1 ./src/shuf-prev \
        -r -i 1000000-1000000 | pv -r > /dev/null
    [ 302MiB/s]
    $ timeout 30 taskset 1 ./src/shuf \
        -r -i 1000000-1000000 | pv -r > /dev/null
    [ 434MiB/s]

* src/shuf.c (print_number): New function.
(write_permuted_numbers, write_random_numbers): Use it.
* tests/shuf/shuf.sh: Add a test case to run 'shuf -i' with varying
numbers of digits to check that the string conversion is correct.
src/shuf.c
tests/shuf/shuf.sh