"??" <[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
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?
>
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
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
> 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
"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
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
甜瓜 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
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