Re: Basic optimization of python.

2008-04-09 Thread Terry Reedy
"??" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] |I wonder whether python compiler does basic optimizations to .py. In general, the answer to such questions depends on the implementation and version thereof. For CPython, you can look at bytecode with the dis module as ano

Re: Basic optimization of python.

2008-04-09 Thread Lou Pecora
In article <[EMAIL PROTECTED]>, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > "Diez B. Roggisch" <[EMAIL PROTECTED]> writes: > > >> Eg: > >> a = 1 + 2 > >> .vs. > >> a = 3 > >> which one is more effective? Does the compiler calculate the result at > >> compile time? How about constant spreading? >

Re: Basic optimization of python.

2008-04-09 Thread bearophileHUGS
ShenLei: > t = self.a.b > t.c = ... > t.d = ... > .vs. > self.a.b.c = ... > self.a.b.d = ... > which one is more effective? Since each dot invokes a hash table lookup, it > may be time consuming. If the compiler can do expression folding, then no > manual folding is needed. Removing dots creatin

Re: Basic optimization of python.

2008-04-09 Thread Diez B. Roggisch
Hrvoje Niksic wrote: > "Diez B. Roggisch" <[EMAIL PROTECTED]> writes: > >>> Eg: >>> a = 1 + 2 >>> .vs. >>> a = 3 >>> which one is more effective? Does the compiler calculate the result at >>> compile time? How about constant spreading? >> >> Algebraic optimizations aren't done AFAIK > > Just try

Re: Basic optimization of python.

2008-04-09 Thread Diez B. Roggisch
> This is safe, and is done: > import dis def f(): x = 1 + 2 > ... dis.dis(f) > 1 0 LOAD_CONST 3 (3) > 3 STORE_FAST 0 (x) > 6 LOAD_CONST 0 (None) > 9 RETURN_VALUE So I stand correct

Re: Basic optimization of python.

2008-04-09 Thread Hrvoje Niksic
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes: >> Eg: >> a = 1 + 2 >> .vs. >> a = 3 >> which one is more effective? Does the compiler calculate the result at >> compile time? How about constant spreading? > > Algebraic optimizations aren't done AFAIK Just try it: Python 2.5.1 (r251:54863, Oct 5

Re: Basic optimization of python.

2008-04-09 Thread [EMAIL PROTECTED]
On Apr 7, 7:30 am, "甜瓜" <[EMAIL PROTECTED]> wrote: > Howdy, > I wonder whether python compiler does basic optimizations to .py. > Eg: > t = self.a.b > t.c = ... > t.d = ... > .vs. > self.a.b.c = ... > self.a.b.d = ... > which one is more effective? Since each dot invokes a hash table lookup, it

Re: Basic optimization of python.

2008-04-09 Thread Diez B. Roggisch
甜瓜 wrote: > Howdy, > I wonder whether python compiler does basic optimizations to .py. > Eg: > t = self.a.b > t.c = ... > t.d = ... > .vs. > self.a.b.c = ... > self.a.b.d = ... > which one is more effective? Since each dot invokes a hash table lookup, > it may be time consuming. If the compile

Basic optimization of python.

2008-04-09 Thread 甜瓜
Howdy, I wonder whether python compiler does basic optimizations to .py. Eg: t = self.a.b t.c = ... t.d = ... .vs. self.a.b.c = ... self.a.b.d = ... which one is more effective? Since each dot invokes a hash table lookup, it may be time consuming. If the compiler can do expression folding, then