Python code written in 1998, how to improve/change it?
Peter Hansen
peter at engcorp.com
Wed Jan 25 15:59:43 EST 2006
Wolfgang Keller wrote:
>>what makes you think that resuming a generator won't involve function
>>calls ?
>
> That was not what I wrote.
>
> I referred to what Peter Hansen <peter at engcorp.com> wrote in
> mailman.821.1137730663.27775.python-list at python.org:
>
>>I believe the more modern approach to this is to use generators in some
>>way, yield each other as the next state. This way you avoid all almost
>>all the function call overhead (the part that takes significant time,
>>which is setting up the stack frame)
>
> The way I understand this, resuming a generator causes less overhead than the
> inital overhead of a function call.
I think in the spirit of avoiding "premature optimization" and all
things related, now is the time to re-inject the other part of my
above-quoted posting, where I also said:
"""
Of course, if you have a state machine with many small states each doing
a tiny bit of processing and you're still concerned over performance,
you probably should be looking into Pysco or Pyrex and avoid making your
code really unreadable.
"""
-Peter
More information about the Python-list
mailing list