Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'python.': 0.02; 'compiler': 0.07; 'subject:same': 0.07; 'think,': 0.07; '"if': 0.09; 'agree,': 0.09; 'imply': 0.09; 'python': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wielding': 0.16; 'subject: ?': 0.16; 'wrote:': 0.18; 'putting': 0.22; "shouldn't": 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'correct': 0.29; "doesn't": 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'that.': 0.31; '(maybe': 0.31; 'changed.': 0.31; 'constant': 0.31; 'implied': 0.31; 'minimal': 0.33; 'subject:the': 0.34; "can't": 0.35; 'no,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'should': 0.36; 'performance': 0.37; 'loss': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'break': 0.61; 'profile': 0.61; "you're": 0.61; 'first': 0.61; 'name': 0.63; 'nobody': 0.68; 'said:': 0.68; 'hoist': 0.93; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=OWy1nisdOTX3Z8pC7KJGhBw5KVvtw4N1c5fD3FXOq8s=; b=WqgxMpJ1xzsKWlwnqXuePtQA8jIcajOfGmnomwt25vBxABbDlw8418cjmf0aD7TogT jBU7l9+2Wo+Gvo6RtrshlHEOmvyUzATFVI1z6UoinoyLTlMg6X2ukb3W2XEEwI2qrsSt qZTWZPDcBwo9lxzOC4/ucggJhzH9VWLBwjRDKr2cpTx24AWaLJUieH6eBA5W1snOU77w N7TUW3lbBG7xFf6TmfIUux/fHbS9ao/bhbf3GSSdvZw2WbzZGZO4Y4BlZbtGFvoDNhny gLfIZW5TYBsME3spGPmgb5R+H63iiRZQoTlWl0KfvY8Bv7aVEOBit8wj0OBvIfYPtHXp ihOw== MIME-Version: 1.0 X-Received: by 10.68.180.131 with SMTP id do3mr19609931pbc.34.1383028744140; Mon, 28 Oct 2013 23:39:04 -0700 (PDT) In-Reply-To: References: Date: Tue, 29 Oct 2013 17:39:04 +1100 Subject: Re: how to avoid checking the same condition repeatedly ? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1383028753 news.xs4all.nl 15985 [2001:888:2000:d::a6]:39635 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:57888 On Tue, Oct 29, 2013 at 5:14 PM, Peter Cacioppi wrote: > Nobody (yes, his name is Nobody) said: > > "If you're sufficiently concerned about performance that you're willing to > trade clarity for it, you shouldn't be using Python in the first place." > > I don't think it's correct to imply that people very concerned about performance should not use Python. (And I agree, Nobody implied that ;) No, I don't think he implied that. You can care about performance while still putting code clarity as a higher priority :) If you actually profile and find that something-or-other is a bottleneck, chances are you can break it out into a function with minimal loss of clarity, and then reimplement that function in C (maybe wielding Cython for the main work). That doesn't compromise clarity. Duplicating a loop to hoist a condition _does_. Of course, in C, you can let the compiler do it for you, but Python can't be sure that it's as constant as you think, so it can't be changed. ChrisA