[Python-ideas] Where-statement (Proposal for function expressions)
Steven D'Aprano
steve at pearwood.info
Fri Jul 17 16:24:30 CEST 2009
On Fri, 17 Jul 2009 11:25:15 pm Gerald Britton wrote:
> Sometimes I use helper functions to make things easier to read.
> However, I don't like unnecessary function calls since they are
> expensive in Python compared to other languages.
That's only a problem if:
(1) Your code actually is too slow; and
(2) You have profiled your code and discovered that the biggest
contributor to your code's slowness is the cost of calling functions,
not the execution time of the functions.
Unless both of these cases hold, then I suggest you are guilty of
premature optimization. Possibly even pessimation -- given the
complexities of CPU caches, memory, swap, etc, it's possible that your
code could be *slower*, not faster, due to your "optimization".
People's intuitions about what's fast and what's slow in Python code are
often completely at odds with reality. Unless you actually have a
problem with slow code that needs solving, my advice is to not worry
about it. Use good algorithms, use tried and tested fast data
structures, and worry about micro-optimizations when you *actually*
need them.
--
Steven D'Aprano
More information about the Python-ideas
mailing list