Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!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.030 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'algorithm': 0.04; '21,': 0.07; 'linux,': 0.07; 'memory.': 0.07; 'subject:code': 0.07; 'subject:How': 0.10; 'thread': 0.14; 'algorithmic': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:make': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'bit': 0.19; 'memory': 0.22; 'putting': 0.22; 'affects': 0.24; 'algorithms.': 0.24; 'helpful': 0.24; 'paul': 0.24; "haven't": 0.24; 'question': 0.24; 'mention': 0.26; 'header:In-Reply-To:1': 0.27; 'unix': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; '-0700,': 0.31; "d'aprano": 0.31; 'faster,': 0.31; 'piece': 0.31; 'steven': 0.31; 'writes:': 0.31; 'probably': 0.32; 'computer.': 0.33; 'programmers': 0.33; 'basic': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'should': 0.36; 'step': 0.37; 'sometimes': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'little': 0.38; 'subject:can': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'even': 0.60; 'hardware': 0.61; "you've": 0.63; 'making': 0.63; 'more': 0.64; 'hours': 0.66; 'between': 0.67; 'effective.': 0.68; 'hour': 0.70; 'money': 0.72; 'jul': 0.74; 'subject:this': 0.83; 'analyzed': 0.84; 'complexity': 0.84; '"how': 0.91; '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=0boVDUoFr0xQpkmas9YQn7JiyqXMhhrzkzeJMV4t/HY=; b=GnmHjcDinOes+ssGAlOcj2+np3g5LFPiVsP+QuwuS7GNH4wAozaGxdUEyB7wqVlXOX VYmYErB4KfL+gGHa0GObTXu9eL4J891ONGq7f5/9y5qJCpPeb5KPsRenY5oN42LTTTwg m1jWT2g6m9lYVCUGkA2upL1yBphwJtZvn1NdIHt2ZtTNp3C/hnZwqQNkD7vIHtXt3adu vJ7GiQyK1YSI/TZ3HtWQnVLf6mPJuwD/L80WUeS11yeoRktOxNPMkoPpqO2zwDKtJIEW 8fy9vpAHCCLMELQwHywo/dedQ5gRzfoQuZ2LEJc6KyzLtI1tSF/BaF4nyrwoG4JD0moZ hvUQ== MIME-Version: 1.0 X-Received: by 10.58.187.4 with SMTP id fo4mr7964457vec.55.1374398513037; Sun, 21 Jul 2013 02:21:53 -0700 (PDT) In-Reply-To: <87fvv8v134.fsf@no-fixed-abode.cable.virginmedia.net> References: <6bf4d298-b425-4357-9c1a-192e6e6cd9f0@googlegroups.com> <51eb6d96$0$29971$c3e8da3$5496439d@news.astraweb.com> <87fvv8v134.fsf@no-fixed-abode.cable.virginmedia.net> Date: Sun, 21 Jul 2013 19:21:52 +1000 Subject: Re: How can I make this piece of code even faster? 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1374398521 news.xs4all.nl 15873 [2001:888:2000:d::a6]:58693 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51000 On Sun, Jul 21, 2013 at 5:11 PM, Paul Rudin wrote: > Steven D'Aprano writes: > >> On Sat, 20 Jul 2013 13:22:03 -0700, pablobarhamalzas asked: >> >> "How can I make this piece of code even faster?" >> >> - Use a faster computer. >> - Put in more memory. >> - If using Unix or Linux, decrease the "nice" priority of the process. >> >> I mention these because sometimes people forget that if you have a choice >> between "spend 10 hours at $70 per hour to optimize code", and "spend >> $200 to put more memory in", putting more memory in may be more cost >> effective. >> > > Sure - but it's helpful if programmers understand a little bit about the > computational complexity of algorithms. If it's just a question of > making each basic step of your algorithm a bit faster, then it may well > be better to spend money on better hardware than on squeezing more out > of your code. OTOH if you've got an n^2 implementation and there's > actually an n.log n solution available then you should probably re-code. I haven't analyzed every suggestion in this thread in detail, but I don't think any of them affects the algorithmic complexity of the code. They're all incremental changes. ChrisA