[pydotorg-www] Python.org - Performance tips page - Avoiding dots section - Question

Sébastien Aubry sebastien.aubry31 at gmail.com
Fri Dec 2 07:32:24 EST 2016

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.


> Hi,
> Thank you for your replies.
> 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).
> I will post this message on the mailing list,
> Regards
> 2016-12-02 13:14 GMT+01:00 Steve Holden <steve at holdenweb.com>:
>> On Fri, Dec 2, 2016 at 11:31 AM, Chris Angelico <rosuav at gmail.com> wrote:
>>> Best would be to start a discussion on the main python-list at python.org
>>> mailing list. There is a LOT to discover about optimization and
>>> timing, and very few of us are experts, but most of us know how very
>>> inexpert we are :)
>> 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).
>> 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
>>     "WORD" * 100000
>> Here's the output from an updated program where the third function simply
>> computes that expression:
>> python3 /tmp/times.py
>> 2.358054072014056
>> 2.167076243989868
>> 0.002145289006875828
>> It seems to me that proves the point exactly: focus on efficient
>> algorithms!
>> 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:
>> "First, make your program work; then, if it doesn't work fast enough,
>> make it work faster"
>> regards
>>  Steve
>> Steve Holden
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pydotorg-www/attachments/20161202/75eed516/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.py
Type: text/x-python
Size: 469 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pydotorg-www/attachments/20161202/75eed516/attachment-0001.py>

More information about the pydotorg-www mailing list