busybox/coreutils
Ron Yorston 8817e285b7 shuf: speed-up when limited output is requested
A user noted that the following command was slower than they
expected:

   busybox shuf -i "1500000000-$(date +%s)" -n 5

At time of writing the range contains 128 million values.  On my
system this takes 7.7s whereas 'shuf' from coreutils takes a
handful of milliseconds.

Optimise BusyBox 'shuf' for cases where -n is specified by stopping
shuffling once the required number of lines have been processed.
On my system the time for the example is reduced to 0.4s.

function                                             old     new   delta
shuf_main                                            520     540     +20
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 20/0)               Total: 20 bytes

v2: Code shrink.  Since outlines <= numlines:
    - the loop in shuffle_lines() only needs to test the value of
      outlines;
    - shuffle_lines() can be called unconditionally.
    Update timing to allow for the 13 million seconds elapsed since v1.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-22 15:40:21 +02:00
..
2018-12-28 03:20:17 +01:00
2021-02-03 20:52:40 +01:00
2021-06-14 20:47:20 +02:00
2021-06-14 20:47:20 +02:00
2021-06-14 20:47:20 +02:00
2021-06-22 10:24:06 +02:00
2018-12-28 03:20:17 +01:00
2021-08-15 23:05:30 +02:00
2021-06-20 15:03:21 +02:00
2018-12-28 03:20:17 +01:00
2018-12-28 03:20:17 +01:00
2021-06-16 17:45:28 +02:00
2021-06-14 20:47:20 +02:00
2021-06-17 13:39:46 +02:00
2021-02-03 20:52:40 +01:00
2021-06-13 01:08:48 +02:00
2020-12-23 02:03:04 +01:00
2017-07-21 09:50:55 +02:00
2021-04-14 15:15:45 +02:00
2021-06-02 04:01:10 +02:00
2018-12-28 03:20:17 +01:00
2021-06-14 20:47:20 +02:00
2018-12-28 03:20:17 +01:00
2020-12-13 19:04:19 +01:00
2018-12-28 03:20:17 +01:00
2021-01-04 13:28:28 +01:00
2018-12-28 03:20:17 +01:00
2021-06-25 00:23:29 +02:00
2018-12-28 03:20:17 +01:00
2021-06-24 13:47:49 +02:00
2017-08-02 14:26:33 +02:00
2021-02-03 20:52:40 +01:00
2018-12-28 03:20:17 +01:00
2018-12-28 03:20:17 +01:00
2018-12-28 03:20:17 +01:00
2021-04-14 15:15:45 +02:00
2020-12-13 19:04:19 +01:00
2018-12-28 03:20:17 +01:00
2021-06-17 00:36:13 +02:00
2021-02-03 20:52:40 +01:00
2021-02-03 20:52:40 +01:00
2018-12-28 03:20:17 +01:00
2018-12-28 03:20:17 +01:00
2019-10-07 14:25:45 +02:00
2020-12-18 04:12:51 +01:00
2017-07-21 09:50:55 +02:00
2021-04-14 15:15:45 +02:00
2021-06-24 23:37:06 +02:00
2018-12-28 03:20:17 +01:00
2018-12-28 03:20:17 +01:00
2021-04-14 15:15:45 +02:00
2021-06-15 10:00:18 +02:00
2018-12-28 03:20:17 +01:00