Java学习从这里JavaVideo开始

JavaVideo java学习从这里开始

当前位置: 主页 > 动态语言 >

What’s New In Python 3.0 Python v3.0.1 documentation(7)

时间:2012-01-26 01:32来源: 作者:admin 点击:
Performance The net result of the 3.0 generalizations is that Python 3.0 runs thepystone benchmark around 10% slower than Python 2.5. Most likely thebiggest cause is the removal of special-casing for

Performance

The net result of the 3.0 generalizations is that Python 3.0 runs the pystone benchmark around 10% slower than Python 2.5. Most likely the biggest cause is the removal of special-casing for small integers. There’s room for improvement, but it will happen after 3.0 is released!

Porting To Python 3.0

For porting existing Python 2.5 or 2.6 source code to Python 3.0, the best strategy is the following:

  • (Prerequisite:) Start with excellent test coverage.
  • Port to Python 2.6. This should be no more work than the average port from Python 2.x to Python 2.(x+1). Make sure all your tests pass.
  • (Still using 2.6:) Turn on the -3 command line switch. This enables warnings about features that will be removed (or change) in 3.0. Run your test suite again, and fix code that you get warnings about until there are no warnings left, and all your tests still pass.
  • Run the 2to3 source-to-source translator over your source code tree. (See for more on this tool.) Run the result of the translation under Python 3.0. Manually fix up any remaining issues, fixing problems until all tests pass again.
  • It is not recommended to try to write source code that runs unchanged under both Python 2.6 and 3.0; you’d have to use a very contorted coding style, e.g. avoiding print statements, metaclasses, and much more. If you are maintaining a library that needs to support both Python 2.6 and Python 3.0, the best approach is to modify step 3 above by editing the 2.6 version of the source code and running the 2to3 translator again, rather than editing the 3.0 version of the source code.

    For porting C extensions to Python 3.0, please see .

    (责任编辑:JavaVideo)
    顶一下
    (0)
    0%
    踩一下
    (0)
    0%
    ------分隔线----------------------------
    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    评价:
    表情:
    用户名: 验证码:点击我更换图片
    栏目列表
    推荐内容