[pydotorg-www] Python.org - Performance tips page - Avoiding dots section - Question
Steve Holden
steve at holdenweb.com
Fri Dec 2 07:14:30 EST 2016
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/97656cf1/attachment.html>
More information about the pydotorg-www
mailing list