X-FeedAbuse: http://nntpfeed.proxad.net/abuse.pl feeded by 78.192.65.63 Path: csiph.com!usenet.pasdenom.info!nntpfeed.proxad.net!news.muarf.org!news.roellig-ltd.de!open-news-network.org!border2.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed2.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '16,': 0.03; 'compiler': 0.07; 'tries': 0.07; 'measure': 0.09; 'wrapper': 0.09; 'cc:addr :python-list': 0.11; "(i'm": 0.16; 'advice,': 0.16; 'dots': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'sequence:': 0.16; 'sat,': 0.16; 'language': 0.16; 'wrote:': 0.18; 'first.': 0.19; "python's": 0.19; 'resolved': 0.19; 'skip:f 30': 0.19; 'example': 0.22; 'cc:addr:python.org': 0.22; "aren't": 0.24; 'own.': 0.24; 'fairly': 0.24; 'cc:2**0': 0.24; 'post': 0.26; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'comments': 0.31; '(unless': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'critical': 0.32; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'should': 0.36; 'performance': 0.37; 'being': 0.38; 'e.g.': 0.38; 'that,': 0.38; 'bad': 0.39; 'sure': 0.39; 'how': 0.40; 'effectively': 0.66; 'of:': 0.68; 'optimized': 0.68; 'delegates': 0.74; '2015': 0.84; 'completely,': 0.84; 'write:': 0.91; 'to:none': 0.92 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:cc :content-type; bh=hU8QYJ1bzGd7hY4s6tx5FO+05x5anCFgtzIc/U3R5FA=; b=Zr8f6P3c+7vUKX1mUPwdlQSvmazvfyODiAfRWCwF7bDBEQ9F2pCiap4MtRPfAQs5AD MWiTXs4T6mzbZFt3N3IqtyojIoUIhLifxXpRupH2ld841BIW52jUdHtamGcCtJRFXApc s9xw4w8Gub9/2hv7lLANK39lSPusRrxprEYx9eCzzLFjRrDoXUCgOqPqVpFphDrMXKqi c1q5urkF9JAc4A9+V4gFhK7AEmVeOCu3NTsMXUTh5q9vWTP76XBO8l5iX2d0scZIII2m S0W/STH6V6bRi4LWL9Jq0LxwkoswqshQHLFOMBqcG0MQcA8eeP4ZJTAdnGxkiusNlAim 6Utg== MIME-Version: 1.0 X-Received: by 10.50.66.146 with SMTP id f18mr1903104igt.14.1431742545268; Fri, 15 May 2015 19:15:45 -0700 (PDT) In-Reply-To: <5556a3a5$0$12989$c3e8da3$5496439d@news.astraweb.com> References: <7JN4x.37133$Q41.15375@fx25.am4> <6w35x.645690$I97.19867@fx31.am4> <874mnfunpn.fsf@elektro.pacujo.net> <87bnhmgqrx.fsf@elektro.pacujo.net> <87twvdsbom.fsf@elektro.pacujo.net> <5556a3a5$0$12989$c3e8da3$5496439d@news.astraweb.com> Date: Sat, 16 May 2015 12:15:44 +1000 Subject: Re: Building CPython From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1431742547 news.xs4all.nl 2862 [2001:888:2000:d::a6]:57249 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90711 On Sat, May 16, 2015 at 11:55 AM, Steven D'Aprano wrote: > but in Python's case it has to be resolved at run-time, so if you care about > speed, you should try to avoid long chains of dots in performance critical > loops. E.g. instead of: > > for x in sequence: > foo.bar.baz.foobar.spam.eggs.cheese(x) > > you can write: > > cheese = foo.bar.baz.foobar.spam.eggs.cheese > for x in sequence: > cheese(x) Like all advice, of course, this should not be taken on its own. Some code tries to avoid long chains of dots by adding wrapper methods: for x in sequence: foo.cheese(x) where foo.cheese() delegates to self.bar.cheese() and so on down the line. That, of course, will be far FAR slower, in pretty much any language (unless the compiler can in-line the code completely, in which case it's effectively being optimized down to the original anyway); the dots aren't as bad as you might think :) Just always remember the one cardinal rule of optimization: MEASURE FIRST. You have no idea how slow something is until you measure it. (I'm not addressing my comments to Steven here, who I'm fairly sure is aware of all of this(!), but it's his post that gave the example that I'm quoting.) ChrisA