Message128795
In Python 3.2, a tuple like (1,-2,3) will not be optimized into a constants at compile time. The tuple is built at run-time. Earlier versions of Python optimized these tuples at compile time.
Here's an example program.
# test.py
from dis import dis
def x(): return (1,2,3)
def y(): return (1,-2,3)
print ("dis x:")
dis(x)
print()
print("dis y:")
dis(y)
The compiler in 3.2rc3 produces code for function y() that builds the tuple at run-time while the tuple in x() is optimized at compile time.
C:\tmp>c:\python32\python --version
Python 3.2rc3
C:\tmp>c:\python32\python test.py
dis x:
3 0 LOAD_CONST 4 ((1, 2, 3))
3 RETURN_VALUE
dis y:
4 0 LOAD_CONST 1 (1)
3 LOAD_CONST 4 (-2)
6 LOAD_CONST 3 (3)
9 BUILD_TUPLE 3
12 RETURN_VALUE
However, under 3.1.3, the tuples in both functions are optimized at compile time.
C:\tmp>c:\python31\python test.py
dis x:
3 0 LOAD_CONST 4 ((1, 2, 3))
3 RETURN_VALUE
dis y:
4 0 LOAD_CONST 4 ((1, -2, 3))
3 RETURN_VALUE
Although the compiled code produced 3.2rc3 is correct, it is much slower than the code generated by 3.1.3. |
|
Date |
User |
Action |
Args |
2011-02-18 17:41:05 | jdharper | set | recipients:
+ jdharper |
2011-02-18 17:41:05 | jdharper | set | messageid: <1298050865.48.0.559427704302.issue11244@psf.upfronthosting.co.za> |
2011-02-18 17:41:04 | jdharper | link | issue11244 messages |
2011-02-18 17:41:04 | jdharper | create | |
|