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?
> >
> > Algebraic optimizations aren't done AFAIK
>
> Just try it:
>
> Python 2.5.1 (r251:54863, Oct 5 2007, 13:36:32)
> [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> dis.dis(lambda: 10+5)
> 1 0 LOAD_CONST 2 (15)
> 3 RETURN_VALUE
Not always. On a Mac running Python 2.4, here's what I get:
In [3]: dis.dis(lambda: 3+4)
1 0 LOAD_CONST 1 (3)
3 LOAD_CONST 2 (4)
6 BINARY_ADD
7 RETURN_VALUE
--
-- Lou Pecora
--
http://mail.python.org/mailman/listinfo/python-list