On Fri, Dec 2, 2016 at 11:31 AM, Chris Angelico <ros...@gmail.com> wrote:
> Best would be to start a discussion on the main python-l...@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
_______________________________________________ pydotorg-www mailing list pydotorg-www@python.org https://mail.python.org/mailman/listinfo/pydotorg-www