Message128795
| Author |
jdharper |
| Recipients |
jdharper |
| Date |
2011年02月18日.17:41:04 |
| SpamBayes Score |
2.6887141e-08 |
| Marked as misclassified |
No |
| Message-id |
<1298050865.48.0.559427704302.issue11244@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|
History
|
|---|
| 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 |
|