[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] seq: speed up the common case by 25x
From: |
Jim Meyering |
Subject: |
Re: [PATCH] seq: speed up the common case by 25x |
Date: |
Fri, 01 Apr 2011 12:16:28 +0200 |
Pádraig Brady wrote:
> On 01/04/11 10:20, Jim Meyering wrote:
>> Pádraig Brady wrote:
>>> seq: speed up the common case by 560%
>>>
>>> * seq.c (print_range): Print a range of numbers
>>> without using if statements for speed.
>>> (print_long_range): Print a range of numbers
>>> using the unix paradigm of using other utils
>>> that do it better.
>>
>> Great idea.
>
>> I get this:
>>
>> $ env time ./seq 10000000 > /dev/null
>> 0.50user 0.06system 0:00.20elapsed 273%CPU (0avgtext+0avgdata
>> 4800maxresident)k
>> ...
>>
>> Compare with the old version's time:
>>
>> 5.06user 0.00system 0:05.08elapsed 99%CPU (0avgtext+0avgdata
>> 2608maxresident)k
>>
>> So here I benefit from parallelism, and end up with not just 560% (5.6x)
>> but a 25x(!) speed-up (on an i7-970).
>
> My April fool's joke has spectacularly backfired.
You choose too well.
seq's performance is a personal pain point,
since I use it regularly, and when it doesn't
scale well, I end up waiting an extra second or two
for larger numbers. "waiting for seq" is annoying
when I know how much faster it can be.
Yeah, yeah, I should just replace it with a function
that runs the pipeline when there's a single number....
Ok. Now I'll use this:
seq()
{
case $#:$1 in 1:[0-9]*) yes | head -n"$1" | cat -n | tr -cd '[0-9\n]';;
*) env seq "$@";; esac
}
It can generate half a billion numbers in 10 seconds:
$ time seq 500000000 |tail -3
500000000
seq 500000000 25.98s user 5.08s system 305% cpu 10.174 total
tail 4.92s user 1.62s system 64% cpu 10.174 total