Philip Rowlands wrote:
The conversion of everything to long doubles internally makes seq a lot
slower than it needs to be in integer cases, I assume from the use of
floating-point multiplication for every line of output:
seq.c:257 x = first + i * step;
$ time seq 100 /dev/null
real0m1.616s
user0m1.610s
sys 0m0.004s
$ time ./myseq 100 /dev/null
real0m0.280s
user0m0.275s
sys 0m0.005s
Would it be possible to detect arguments which require no
floating-point, and handle them with integer addition?
I've noticed that too, but it wasn't on my priority list.
Here are some alternatives and timings:
$ time seq 100 /dev/null
real0m1.236s
$ time yes '' | nl -ba -w1 -s' ' | head -n100 /dev/null
real0m0.623s
$ time shuf -i 1-100 --random-source=/dev/zero /dev/null
real0m0.568s
# This uses ascii add from getlimits.c and is arbitrary precision
$ time seq2 1 1 100 /dev/null
real0m0.379s
# simple for(...) printf(i);
$ time seq.simple /dev/null
real0m0.268s
# cat -n uses ascii add optimised for +1 case (next_line_num)
$ time yes '' | cat -n | head -n100 /dev/null
real0m0.142s
cheers,
Pádraig.