Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.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.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; '""")': 0.09; 'builtin': 0.09; 'am,': 0.12; 'def': 0.14; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'imho,': 0.16; 'subject:() ': 0.16; '\xa0you': 0.16; 'wrote:': 0.18; 'received:209.85.210.174': 0.18; 'received:mail-iy0-f174.google.com': 0.18; 'wrote': 0.19; 'maybe': 0.21; 'header:In-Reply-To:1': 0.23; 'code': 0.25; 'import': 0.28; 'message-id:@mail.gmail.com': 0.29; "it'd": 0.30; 'really,': 0.30; "didn't": 0.30; 'subject:?': 0.31; 'nov': 0.31; 'tue,': 0.32; 'to:addr:python-list': 0.32; 'but,': 0.34; 'function.': 0.34; 'david': 0.34; 'fair': 0.36; 'but': 0.37; 'think': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; "it's": 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.40; 'more': 0.60; '2011': 0.62; 'making': 0.67; 'specialized': 0.72 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=udLziO9KSZ1VW0AmeQ3NNDw6jOUyQmQ1Fi43G4LuLLA=; b=QO8a4LIs3cnIQorNsJljE3/RJNHnegAqBMHkcIqhWLSgf34TwIBt2Z8grKBJyg9qy4 dmj30Sa7lyn7UfxuOVY2+e3KnukQfD4/Yme+ne4nJR4HL489Oa/IYYFd/iGGW80/0ZSe CmbwarTJDaai5T7JlqsWgR/FStVaYvWwSVtH4= MIME-Version: 1.0 In-Reply-To: <436fb6a3-1075-45a6-8f93-5612d050b11a@q35g2000prh.googlegroups.com> References: <436fb6a3-1075-45a6-8f93-5612d050b11a@q35g2000prh.googlegroups.com> Date: Tue, 8 Nov 2011 09:06:56 +1100 Subject: Re: all() is slow? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1320703618 news.xs4all.nl 6968 [2001:888:2000:d::a6]:35818 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15443 On Tue, Nov 8, 2011 at 8:46 AM, david vierra wrote= : > But, you didn't write an all() function. =A0You wrote a more specialized > 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): exec("""def tmp_all(x): for a in x: if not ("""+code+"""): return False return True """) return 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