Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'exec': 0.07; 'python': 0.08; '""")': 0.09; 'builtin': 0.09; 'am,': 0.12; 'def': 0.14; 'cc:addr:python-list': 0.15; 'mon,': 0.15; '5:06': 0.16; 'imho,': 0.16; 'received:209.85.210.42': 0.16; 'received:mail- pz0-f42.google.com': 0.16; 'stdlib.': 0.16; 'subject:() ': 0.16; 'tongue': 0.16; 'url:hg': 0.16; '\xc2\xa0if': 0.16; '\xc2\xa0you': 0.16; 'wrote:': 0.18; 'slightly': 0.19; 'wrote': 0.19; 'cc:no real name:2**0': 0.21; 'maybe': 0.21; 'header:In-Reply-To:1': 0.23; 'cc:2**0': 0.25; 'code': 0.25; 'url:mailman': 0.27; 'import': 0.28; 'cc:addr:python.org': 0.29; 'message-id:@mail.gmail.com': 0.29; 'invoke': 0.30; "it'd": 0.30; 'really,': 0.30; 'chris': 0.30; "didn't": 0.30; 'subject:?': 0.31; 'nov': 0.31; 'pm,': 0.31; 'tue,': 0.32; 'url:listinfo': 0.32; 'but,': 0.34; 'function.': 0.34; 'david': 0.34; 'url:python': 0.35; 'clearly': 0.36; 'fair': 0.36; 'but': 0.37; 'think': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'url:org': 0.38; "it's": 0.39; 'subject:: ': 0.39; 'received:209': 0.40; 'more': 0.60; '2011': 0.62; 'making': 0.67; 'specialized': 0.72; 'skip:\xc2 10': 0.73; 'url:lib': 0.84; 'stupid': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=Y56aiXces+h2sBPB75/HAQvq7kfGHLtIelW1F6zLsXg=; b=f16YVNNof1vQ7DPJE5Ue8i2XNq4L/csfMkQLq8cJ/+uI4kbLyGDxxoFA2Rw/R6QcGg 2wPFYW9yuKXZ1a0p92vf+A+yXsqVfgoi7fn5hqect8y9GOA/nzgBNyXC1gZLbLQ6MsTt +mFWdb8SybAaCjHWOOOIsTw6ZafEPdZOsmo/U= MIME-Version: 1.0 In-Reply-To: References: <436fb6a3-1075-45a6-8f93-5612d050b11a@q35g2000prh.googlegroups.com> From: Devin Jeanpierre Date: Tue, 8 Nov 2011 19:44:18 -0500 Subject: Re: all() is slow? To: Chris Angelico Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1320799508 news.xs4all.nl 6891 [2001:888:2000:d::a6]:35110 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15488 Clearly what we need is a modern hygienic macro system to avoid this exec m= ess! defmacro defall(name, cond): def name(lst): for a in lst: if not cond: return False return True invoke defall(all, cond) Only slightly tongue in cheek. We have that stupid exec trick in the Python stdlib. It has to die. http://hg.python.org/cpython/file/6bf07db23445/Lib/collections/__init__.py#= l240 Devin On Mon, Nov 7, 2011 at 5:06 PM, Chris Angelico wrote: > On Tue, Nov 8, 2011 at 8:46 AM, david vierra wro= te: >> But, you didn't write an all() function. =C2=A0You wrote a more speciali= zed >> allBoolean() function. I think this comparison is more fair to the >> builtin all(): > > So really, it's not "all() is slow" but "function calls are slow". > Maybe it'd be worthwhile making an all-factory: > > def my_all(code,lst): > =C2=A0 =C2=A0exec("""def tmp_all(x): > =C2=A0 =C2=A0 =C2=A0 =C2=A0for a in x: > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if not ("""+code+"""): return Fa= lse > =C2=A0 =C2=A0 =C2=A0 =C2=A0return True > """) > =C2=A0 =C2=A0return tmp_all(lst) > timeit.timeit('my_all("a in (True, False)",x)','from __main__ import > my_all,x',number=3D10) > > Bad code imho, but it _is_ faster than both the original and the builtin. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list >