cut: reduce CPU overhead in determining item to output
commitef9db5735a401f60eb5b4a18a365bf1ece525053
authorCojocaru Alexandru <xojoc@gmx.com>
Sun, 28 Apr 2013 02:03:45 +0000 (28 03:03 +0100)
committerPádraig Brady <P@draigBrady.com>
Mon, 29 Apr 2013 16:54:39 +0000 (29 17:54 +0100)
tree836c6d92830d2fa3037e2378e4277dc634bb81ef
parent3e466ad05181d95057e6612ff11059c91396cd0e
cut: reduce CPU overhead in determining item to output

print_kth() is the central function of cut used to
determine if an item is to be output or not,
so simplify it by moving some logic outside.
Benchmark results for this change are:

$ yes abcdfeg | head -n1MB > big-file
$ for c in orig split; do
    src/cut-$c 2>/dev/null
    echo -ne "\n== $c =="
    time src/cut-$c -b1,3 big-file > /dev/null
  done

== orig ==
real    0m0.111s
user    0m0.108s
sys     0m0.002s

== split ==
real    0m0.088s
user    0m0.081s
sys     0m0.007s

* src/cut.c (print_kth): Refactor a branch to outside the function.
Related to http://bugs.gnu.org/13127
src/cut.c
tests/misc/cut-huge-range.sh