[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: compgen is slow for large numbers of options

From: Chet Ramey
Subject: Re: compgen is slow for large numbers of options
Date: Mon, 19 Mar 2012 19:08:19 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2

On 3/19/12 6:13 PM, Geir Hauge wrote:
> 2012/3/19 Chet Ramey <address@hidden>:
>> I will look at optimizing that function, but it's always going to take time
>> to plow through 300K when you have to split it into words.  (There's not
>> actually any word splitting of consequence happening with your second
>> example using the pipeline.)
> Letting compgen do the command substitution speeds it up considerably
> $ time compgen -W "`seq 1 500000`" 1794 >/dev/null
> 175.253
> $ time compgen -W '`seq 1 500000`' 1794 >/dev/null
> 2.347

That's an excellent suggestion.  Instead of splitting into 500000 words
and then expanding each one, you do one word expansion that ends up
being split into 500000 words.  The command substitution is more
efficiently performed by the second invocation.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]