Overhead for local assignments (was: A better self)

Kerim Borchaev warkid at storm.ru
Tue Jul 23 14:36:09 EDT 2002


Hello Louis,

  sorry if this message sounds offensive - it isn't supposed to ;-)

Tuesday, July 23, 2002, 8:11:00 PM, you wrote:

...

LMP> xRange time= 0.15076
LMP> tuple assign time= 0.958203999999
LMP> line time= 0.799539
LMP> fcn1 (class call) time= 1.508272
LMP> fcn2 (local call) time= 1.256834

...

LMP> Method (2) is fastest as some people suggested.  (1) does seem to
LMP> involve some time creating and destroying a tuple as suggested.  (3) is
LMP> the worst, by a factor of 2!  So if you have lots of class function
LMP> calls, assign the function to a local variable, but even better, avoid
LMP> using the function calls to just calculate a formula, if possible.

It feels like a general advice.
"lots of class function" - it lets everyone decide the meaning of
"lots" for himself; or how should I treat "to just calculate a
formula" - is it for any code that involves "the math"?

So I'd give another general advice:

- Make the code as clean as possible(using functions, methods - all
  the best of the language ) BEFORE you discover that it works too slow.
   
- And only whan you're absolutely sure(the tests show) that
  it's slow for your needs - think about optimization.
  
- Then profile test cases of interest to find out which pieces of code are
  worth optimizing to get a valuable speedup.

- Then optimize. ...or not yet?

Best regards,
 Kerim                            mailto:warkid at storm.ru






More information about the Python-list mailing list