V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
codists
V2EX  ›  Python

Python 3.14 采用新型解释器,速度提高-3%~30%

  •  
  •   codists ·
    codists · 7 天前 · 5599 次点击

    Python 官方文档( https://docs.python.org/3.14/whatsnew/3.14.html#a-new-type-of-interpreter) :

    A new type of interpreter based on tail calls has been added to CPython. For certain newer compilers, this interpreter provides significantly better performance. Preliminary numbers on our machines suggest anywhere from -3% to 30% faster Python code, and a geometric mean of 9-15% faster on pyperformance depending on platform and architecture. The baseline is Python 3.14 built with Clang 19 without this new interpreter.

    其实我很想知道,这种性能测试的结果到底准不准?熟悉这方面的大佬来聊聊。

    33 条回复    2025-02-14 14:55:53 +08:00
    vkillwucy
        1
    vkillwucy  
       7 天前 via Android   ❤️ 1
    盲猜一个不准
    crackidz
        2
    crackidz  
       7 天前   ❤️ 1
    https://github.com/faster-cpython/benchmarking-public 可以看下他们跑的基准测试都跑了哪些场景
    xgdgsc
        3
    xgdgsc  
       7 天前 via Android   ❤️ 1
    准肯定是准的,就是真需要这个性能的早都转 Julia rust cpp 了
    alwaysol
        4
    alwaysol  
       6 天前   ❤️ 2
    提高-3%?
    strobber16
        5
    strobber16  
       6 天前 via Android   ❤️ 2
    go 1.24 使用新型 runtime ,速度提高 2%~3%
    coolcoffee
        6
    coolcoffee  
       6 天前   ❤️ 1
    我怎么感觉是 python 之前的性能实在是太差,所以显得进步空间贼大。

    就以 100 为单位,提升 5%-30%也就是 105 ~ 130 。但是 C++可能在 1000 。
    GeekGao
        7
    GeekGao  
       6 天前   ❤️ 1
    @coolcoffee 没法相比其他语言,只能对比自己。
    yh7gdiaYW
        8
    yh7gdiaYW  
       6 天前   ❤️ 1
    3.11 的时候也说有提升,给出的性能测试结果也不错,结果落到我们的业务场景(主要是大量数据的遍历和计算,有一些环节没法拆到 C++)中速度还变慢了...
    JokerSH
        9
    JokerSH  
       6 天前   ❤️ 1
    @alwaysol 原文中是换行的连词符号
    uni
        10
    uni  
       6 天前   ❤️ 1
    我挺喜欢 python 的,但是 py 连 nodejs 的性能都比不过。。。
    ninjashixuan
        11
    ninjashixuan  
       6 天前   ❤️ 1
    fastpython 项目多少年了,这提升龟速翻五倍的目标是不是遥遥无期了。
    ninjashixuan
        12
    ninjashixuan  
       6 天前   ❤️ 3
    @uni 什么叫连,人 v8 引擎一直是高性能的标杆吧。
    tsanie
        13
    tsanie  
       6 天前   ❤️ 1
    @JokerSH #9
    原文就是 from -3% to 30% faster 。
    连词符号是在 interpreter 这个单词,而且是 css hyphens ,复制文本出来是没有连词符的。
    crackidz
        14
    crackidz  
       6 天前   ❤️ 1
    @yh7gdiaYW 这是常见的无感提速问题了,某些场景下就是会慢... 算是一种 trade off
    Jinnrry
        15
    Jinnrry  
       6 天前   ❤️ 1
    都用 python 了,还在乎性能吗?真需要性能,拿 c 、rust 写底层,python 调用不就行了?胶水语言就应该干胶水语言干的活
    adoal
        16
    adoal  
       6 天前   ❤️ 1
    @alwaysol 意思就是有的代码运行可能会变慢一点。
    Shatyuka
        17
    Shatyuka  
       6 天前   ❤️ 1
    太厉害了 python ,很难说是不是之前太慢显得提升很多。

    附 3.11 的更新日志: https://docs.python.org/3.11/whatsnew/3.11.html#faster-cpython
    CPython 3.11 is an average of 25% faster than CPython 3.10 as measured with the pyperformance benchmark suite, when compiled with GCC on Ubuntu Linux. Depending on your workload, the overall speedup could be 10-60%.
    lesismal
        18
    lesismal  
       6 天前   ❤️ 1
    300%也还是慢...
    jjx
        19
    jjx  
       6 天前   ❤️ 1
    因为从 2 到 3 , 就慢了

    现在只是恢复到 2 的水准,哈哈
    JokerSH
        20
    JokerSH  
       6 天前   ❤️ 1
    @tsanie 你说的对,是我想当然了,很抱歉。感谢指正。
    ChrisFreeMan
        21
    ChrisFreeMan  
       6 天前   ❤️ 1
    @lesismal 不如 3500 倍快的 python 杀手 Mojo Lang🐶
    JokerSH
        22
    JokerSH  
       6 天前   ❤️ 1
    @alwaysol 抱歉,我之前给你的回复是错误的,请看下面 13 楼 tsanie 的解释
    Binwalker
        23
    Binwalker  
       6 天前   ❤️ 1
    都用 python 了,还想效率,就算提升 100%也没什么用
    wionch
        24
    wionch  
       6 天前   ❤️ 1
    GIL 锁还在没?
    iorilu
        25
    iorilu  
       6 天前   ❤️ 1
    python 根本不在乎性能

    需要性能, 用 rust 可能就提升几十上百倍了
    vsheyan
        26
    vsheyan  
       6 天前   ❤️ 1
    库是真的多用就完了
    zhouquanbest
        27
    zhouquanbest  
       6 天前   ❤️ 1
    卖家秀
    你往前看看过去版本的性能优化 Log ,吹的也不小
    CodeCodeStudy
        28
    CodeCodeStudy  
       5 天前   ❤️ 2
    @JokerSH #9 按 F12 看了网页源码,确定是-3%而不是连字符
    llsquaer
        29
    llsquaer  
       5 天前
    python3.10 路过。。才升为主力开发版本
    JokerSH
        30
    JokerSH  
       5 天前   ❤️ 1
    @CodeCodeStudy 感谢指正。
    dragondove
        31
    dragondove  
       5 天前   ❤️ 1
    @wionch 现阶段的 nogil 只能帮助提升多线程的性能,单线程的性能反而会下降,你可以自己构建 python 3.13 ,构建参数有 gil 相关的,现在已经可以关闭了。
    codists
        32
    codists  
    OP
       5 天前
    感谢各位的解答与观点,特别感谢 @yh7gdiaYW 的实际经验分享,这是我比较想看到的。
    uni
        33
    uni  
       5 天前
    @ninjashixuan #12 因为同为脚本语言,定位相似
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1017 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 20:40 · PVG 04:40 · LAX 12:40 · JFK 15:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.