Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Paul Rudin Newsgroups: comp.lang.python Subject: Re: How can I make this piece of code even faster? Date: Sun, 21 Jul 2013 08:11:59 +0100 Lines: 25 Message-ID: <87fvv8v134.fsf@no-fixed-abode.cable.virginmedia.net> References: <6bf4d298-b425-4357-9c1a-192e6e6cd9f0@googlegroups.com> <51eb6d96$0$29971$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain X-Trace: individual.net h4apqANyxy3FZ4Ry3oZ5KwthDxBj/LxNn4FReybhalAui/Pewg X-Orig-Path: hal9000.rudin.co.uk!not-for-mail Cancel-Lock: sha1:1EOTLGQSAPBTIPIPPGCTvBheH+U= sha1:puBmJAqhfYLk3gpedXJ3SocgTWY= User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) Xref: csiph.com comp.lang.python:50997 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. Of course if what you've got is actually adequate for your use-case then it maybe that you don't actually need to do anything at all...