diff options
author | Ron Yorston | 2021-08-07 09:41:49 +0100 |
---|---|---|
committer | Denys Vlasenko | 2021-08-22 15:40:21 +0200 |
commit | 8817e285b7ce071a27c366a2a602d3ca162b08ba (patch) | |
tree | f3f6e68561420ba8e2f13ea25f81257ed38452f1 /shell/ash_test/ash-quoting/dollar_altvalue1.right | |
parent | 74c4f356aee9c64978a881e5760055d0e3510a6a (diff) | |
download | busybox-8817e285b7ce071a27c366a2a602d3ca162b08ba.zip busybox-8817e285b7ce071a27c366a2a602d3ca162b08ba.tar.gz |
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>
Diffstat (limited to 'shell/ash_test/ash-quoting/dollar_altvalue1.right')
0 files changed, 0 insertions, 0 deletions