[Python-Dev] python optimization
Greg Ewing
greg.ewing at canterbury.ac.nz
Fri Sep 16 05:55:41 CEST 2005
Brett Cannon wrote:
>>I don't know to what extent these kind of optimizations are available to
>>cpython. For example, are constant calculations removed from loops?
>
> If you mean ``2+3``, then yes.
Actually, no. Constant folding *could* be done, but it currently isn't:
>>> def f():
... return 2+3
...
>>> import dis
>>> dis.dis(f)
2 0 LOAD_CONST 1 (2)
3 LOAD_CONST 2 (3)
6 BINARY_ADD
7 RETURN_VALUE
8 LOAD_CONST 0 (None)
11 RETURN_VALUE
>>>
--
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
greg.ewing at canterbury.ac.nz +--------------------------------------+
More information about the Python-Dev
mailing list