Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #15127

Re: Fast recursive generators?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'skip': 0.04; 'received:verizon.net': 0.07; 'terry': 0.07; 'filter,': 0.09; 'func': 0.09; 'generators': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'def': 0.15; 'argument': 0.15; 'considerably': 0.16; 'hammer': 0.16; 'reedy': 0.16; 'what?': 0.16; 'wrote:': 0.16; 'jan': 0.19; '(which': 0.19; 'seems': 0.20; 'header:In-Reply-To:1': 0.22; 'pm,': 0.24; 'string': 0.26; 'function': 0.27; 'problem': 0.28; 'yield': 0.29; '---': 0.29; 'example': 0.30; 'not.': 0.30; 'list).': 0.30; 'values,': 0.30; 'subject:?': 0.31; 'seem': 0.31; 'michael': 0.31; 'values': 0.32; 'list': 0.32; 'usually': 0.32; 'actually': 0.33; 'to:addr:python- list': 0.33; 'header:User-Agent:1': 0.34; 'header:X-Complaints- To:1': 0.35; 'list.': 0.35; 'problem.': 0.36; 'sequence': 0.37; 'passed': 0.37; 'using': 0.37; 'list,': 0.37; 'but': 0.37; 'not,': 0.38; 'think': 0.38; 'received:org': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'more': 0.60; 'your': 0.61; 'hope': 0.61; 'grab': 0.66; 'making': 0.67; '"for': 0.67; 'applicable': 0.68; 'saw': 0.69; 'pre-existing': 0.84; 'value):': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Fast recursive generators?
Date Fri, 28 Oct 2011 22:27:40 -0400
References <CAG+HS+53dEnqLK-7P7TWZJmsmQd6ommzyd4SJ1uO=i11rfiz=A@mail.gmail.com> <j8f497$qjc$1@dough.gmane.org> <CAG+HS+5Loxsz927ttCgpvHGLV5VLR1zrriK8KCuz+uwFE-1FUA@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-74-109-121-73.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20110812 Thunderbird/6.0
In-Reply-To <CAG+HS+5Loxsz927ttCgpvHGLV5VLR1zrriK8KCuz+uwFE-1FUA@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2299.1319855279.27778.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1319855279 news.xs4all.nl 6888 [2001:888:2000:d::a6]:40179
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:15127

Show key headers only | View raw


On 10/28/2011 8:49 PM, Michael McGlothlin wrote:

>> Better to think of a sequence of values, whether materialized as a 'list' or
>> not.
>
> The final value will actually be a string but it seems it is usually
> faster to join a list of strings than to concat them one by one.

.join() takes an iterable of strings as its argument

>> Comprehensions combine map and filter, both of which conceptually work on
>> each item of a pre-existing list independently. (I am aware that the
>> function passed can stash away values to create dependence.
>
> The problem is I don't really have a pre-existing list.

So, as I said, map, filter, and comprehensions are not applicable to 
your problem.

>> def do(func, N, value):
>>     yield value
>>     for i in range(1,N):
>>         value = func(value)
>>         yield value
>>
>> For more generality, make func a function of both value and i.
>> If you need a list, "l = list(do(f,N,x))", but if you do not, you can do
>> "for item in do(f,N,x):" and skip making the list.
>
> Generators seem considerably slower than using comprehension or
> map/filter

So what? A saw may cut faster than a hammer builds, but I hope you don't 
grab a saw when you need a hammer.

 > /reduce.

Do you actually have an example where ''.join(reduce(update, N, start)) 
is faster than ''.join(update_gen(N, start))? Resuming a generator n 
times should be *faster* than n calls to the update function of reduce 
(which will actually have to build a list).

---
Terry Jan Reedy

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Fast recursive generators? Terry Reedy <tjreedy@udel.edu> - 2011-10-28 22:27 -0400

csiph-web