A better self

Andreas Kostyrka andreas at kostyrka.priv.at
Wed Jul 24 11:05:28 EDT 2002


Am Sam, 2002-07-20 um 17.33 schrieb Louis M. Pecora:
> So, only the Python secret brotherhood gets to see The List?
Well, it's better this way. The List [of speedup tricks] contains
usually ugly things. :)

So it's quite correct that it is only presented to the truebelievers. :)

There is number of things, but the more important things to keep in
mind:

- function calls are relativly expensive in Python. At least compared to
more static and compiled languages.
- immutable objects need to be copied to be modified.
  str1+str2+str3+str4+str5+str6+str7+str8 is usually slower than
  "".join([str1,str2,str3,str4,str5,str6,str7,str8])
- every dot access is a dictionary lookup. And python usually cannot do 
  constant folding, etc., because every call is dynamic:
  So instead of
  for i in xrange(<huge value>):
    x="".join(...)
  one might write:
  fjoin="".join
  for i in xrange(<huge value>):
    x=fjoin(...)

There are certainly other rules, but these are the ones that came to my
mind. :)

Andreas





More information about the Python-list mailing list