<div dir="ltr"><div>Hi,<br></div><div>I have updated my example, so that it exactly matches the website. Now it is Ok. I don't see what was wrong in my first example.<br><br></div><div>Regards<br></div><div>Sébastien<br><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div><div><div>Hi,<br></div>Thank you for your replies.<br></div><br>I
 fully understand your point, Steve, and agree with it, but I just 
wanted to check if one should really "Avoid dots" as suggested on the 
Python website itself. I wonder if this section should not be removed, 
since the given example itself is wrong (I mean slower).<br></div>I will post this message on the mailing list, <br><br></div>Regards<div class="gmail_extra"><br><div class="gmail_quote">2016-12-02 13:14 GMT+01:00 Steve Holden <span dir="ltr"><<a href="mailto:steve@holdenweb.com" target="_blank">steve@holdenweb.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><span class="gmail-"><div class="gmail_quote">On Fri, Dec 2, 2016 at 11:31 AM, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div id="gmail-m_2154350479731866353gmail-:113" class="gmail-m_2154350479731866353gmail-a3s gmail-m_2154350479731866353gmail-aXjCH gmail-m_2154350479731866353gmail-m158bf4dad002c432">Best would be to start a discussion on the main <a href="mailto:python-list@python.org" target="_blank">python-list@python.org</a><br>
mailing list. There is a LOT to discover about optimization and<br>
timing, and very few of us are experts, but most of us know how very<br>
inexpert we are :)<br></div></blockquote></div><br></span>Also, remember that premature optimization is the root of all evil in programming! The kind of gains to be expected by hoisting attribute lookups out of the loop will usually be lost in the noise compared with gains to be made from use of superior algorithms (often involving refactoring inappropriate data structures).</div><div class="gmail_extra"><br></div><div class="gmail_extra">In the particular code you submitted I saw that the "optimized" version is about 10% slower than the "non-optimzed" version. Until you get your algorithm correct, it's hardly worth worrying about. After all, the Pythonic way to create the value you want is simply</div><div class="gmail_extra"><br></div><div class="gmail_extra">    "WORD" * 100000</div><div class="gmail_extra"><br></div><div class="gmail_extra">Here's the output from an updated program where the third function simply computes that expression:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">python3 /tmp/times.py</div><div class="gmail_extra">2.358054072014056</div><div class="gmail_extra">2.167076243989868</div><div class="gmail_extra">0.002145289006875828</div><div><br></div><div>It seems to me that proves the point exactly: focus on efficient algorithms!</div><div><br></div><div>I understand you may simply be exploring python's behaviour, which is great, but as far as production work goes, the old saw is true:</div><div><br></div><div>"First, make your program work; then, if it doesn't work fast enough, make it work faster"</div><div><br></div><div>regards</div><div> Steve</div><span class="gmail-HOEnZb"><font color="#888888"><br clear="all"><div><div class="gmail-m_2154350479731866353gmail_signature"><div dir="ltr">Steve Holden<br></div></div></div>
</font></span></div></div>
</blockquote></div><br></div></blockquote></div>