V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
wdwwtzy
V2EX  ›  程序员

这个各大语言性能测试结果挺有意思

  •  3
     
  •   wdwwtzy · 2022-06-27 13:06:40 +08:00 · 20178 次点击
    这是一个创建于 640 天前的主题,其中的信息可能已经有所发展或是发生改变。
    182 条回复    2022-10-29 16:50:11 +08:00
    1  2  
    INCerry
        1
    INCerry  
       2022-06-27 13:21:46 +08:00   ❤️ 19
    C# yyds
    dcsuibian
        2
    dcsuibian  
       2022-06-27 13:28:14 +08:00   ❤️ 2
    知道 Python 慢,不过没想到有这么慢
    liushuangbill
        3
    liushuangbill  
       2022-06-27 13:29:57 +08:00   ❤️ 7
    Node.js 还挺快
    v23x
        4
    v23x  
       2022-06-27 13:30:57 +08:00
    Rust the only true god
    kerrspace
        5
    kerrspace  
       2022-06-27 13:34:31 +08:00
    有没有大佬来说一下 rust 替代 c++的前景
    qrobot
        6
    qrobot  
       2022-06-27 13:35:15 +08:00
    Java 不是性能取决于 JVM 么?
    zmqiang
        7
    zmqiang  
       2022-06-27 13:36:08 +08:00
    看了两遍才发现图的左边和右边顺序不一样
    min
        8
    min  
       2022-06-27 13:37:05 +08:00   ❤️ 1
    C#可以啊
    icyalala
        9
    icyalala  
       2022-06-27 13:38:42 +08:00
    这有另外一个更知名的: https://github.com/kostya/benchmarks
    ragnaroks
        10
    ragnaroks  
       2022-06-27 13:39:05 +08:00
    我虽然经常黑 java ,但是 java 不应该这么慢,最多落后 dotnet 两个身位,如果这个图是 dotnet 6 、java 11 那当我没说
    Phishion
        11
    Phishion  
       2022-06-27 13:41:37 +08:00   ❤️ 1
    python3 倒数第一几个意思?后面没有其他语言了?
    INCerry
        12
    INCerry  
       2022-06-27 13:42:38 +08:00   ❤️ 4
    @ragnaroks 看了下原链接 https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/csharp.html
    C# .NET SDK 6.0.101
    Java openjdk 18 2022-03-22 OpenJDK 64-Bit Server VM
    Leviathann
        13
    Leviathann  
       2022-06-27 13:43:11 +08:00
    swift 是不是最慢的 native 语言
    mosfet
        14
    mosfet  
       2022-06-27 13:44:15 +08:00
    我记得 C# JAVA GO 都差不多的,半斤八俩
    ragnaroks
        15
    ragnaroks  
       2022-06-27 13:46:02 +08:00
    @INCerry 我没有实际测试,就不发表评论了,不过根据我的个人经验,dotnet 6 和 java 17 差距很小
    ecnelises
        16
    ecnelises  
       2022-06-27 13:46:05 +08:00 via iPhone
    OCaml 的速度有点令人惊喜啊(虽然 Haskell 更快)。

    Swift 直接毙了吧,背靠 LLVM 的静态语言搞成这样,不知道加入所有权后能提高多少。
    MakHoCheung
        17
    MakHoCheung  
       2022-06-27 13:51:34 +08:00
    Swift 不是编译成二进制的吗,这么慢
    bk201
        18
    bk201  
       2022-06-27 13:51:56 +08:00
    java 的性能有这么差吗?
    buxudashi
        19
    buxudashi  
       2022-06-27 13:53:05 +08:00
    lua 不是说很好吗?怎么连 PHP 都不如?
    makelove
        20
    makelove  
       2022-06-27 13:57:00 +08:00
    我大 javascript 神一样的存在
    nmap
        21
    nmap  
       2022-06-27 13:57:47 +08:00
    go 比起 c/c++/rust 还是差不少啊😥
    liuxu
        22
    liuxu  
       2022-06-27 13:59:09 +08:00
    @kerrspace C++不清楚,linux 内核下个版本 5.20 要合并 rust 的基础设施了,现在 5.19 ,https://www.phoronix.com/scan.php?page=news_item&px=Rust-For-Linux-5.20-Possible
    iyaozhen
        23
    iyaozhen  
       2022-06-27 14:03:16 +08:00   ❤️ 1
    @Phishion Python 是真的拉胯 很容易遇到性能瓶颈
    ifdef
        24
    ifdef  
       2022-06-27 14:04:55 +08:00
    我大 javascript 神一样的存在
    Phishion
        25
    Phishion  
       2022-06-27 14:09:08 +08:00
    @iyaozhen 但是我觉得上面好些已经是事实上的 dead 语言了,或者根本没什么人用,可见以 Python3 的使用人群来说,性能也不是什么问题。
    ragnaroks
        26
    ragnaroks  
       2022-06-27 14:12:38 +08:00
    @buxudashi lua 应该有两种用法,一个是基于 luajit 动态解析运行,一个是(开发游戏常用)直接编译成 lua.dll ,前者性能差到以为是网络卡了,后者应该在 c/c++ 的十倍以内
    Cyshall
        27
    Cyshall  
       2022-06-27 14:13:40 +08:00   ❤️ 1
    c# 为什么这么屌?
    princelai
        28
    princelai  
       2022-06-27 14:16:15 +08:00
    这个一年多前就讨论过了啊,我也画过图,https://www.v2ex.com/t/776893#reply51

    另外 python 慢是因为他是用纯内置语言来实现算法,但实际上 python 除了调用 C++和 fortrain 写的东西外,在 numpy 和 numba 等技术加持下,python 写数值计算和算法并不慢,甚至能超过 90%的语言,我是没遇到过什么瓶颈。
    luob
        29
    luob  
       2022-06-27 14:17:26 +08:00   ❤️ 1
    基本符合日常经验,c/c++开了 o2 之后谁也打不过,go 和 java 一个水平,比 nodejs 快 30-40%,python 比主流语言慢两个数量级(
    tabris17
        30
    tabris17  
       2022-06-27 14:17:30 +08:00   ❤️ 1
    壮哉!大 python
    iyaozhen
        31
    iyaozhen  
       2022-06-27 14:17:45 +08:00
    @Phishion 不是说人多就没有性能问题。

    Python 主要是乘着 AI 的大船,不然使用量会少很多。这里说的是语音本身,但 Python 的特色是胶水语言和 C 紧密结合,这块大大提高了性能天花板
    Phishion
        32
    Phishion  
       2022-06-27 14:30:11 +08:00
    @iyaozhen 实际体验我也没觉得 Python 比主流慢几十倍这个样子,我不知道你用 Python3 做什么开发,能很容易就遇到性能瓶颈?
    min
        33
    min  
       2022-06-27 14:31:53 +08:00
    @mosfet go 内存占用小一些,速度和 java C#半斤八两
    Mark24
        34
    Mark24  
       2022-06-27 14:35:35 +08:00
    ruby 可以开 JIT ,会再快一倍左右
    damngood
        35
    damngood  
       2022-06-27 14:35:54 +08:00
    swift 和 go 的内存消耗指标很不错.
    iyaozhen
        36
    iyaozhen  
       2022-06-27 14:37:02 +08:00
    @Phishion web 开发,或者一些压测工具。非 AI
    INCerry
        37
    INCerry  
       2022-06-27 14:41:47 +08:00   ❤️ 1
    @min
    在他们测的这个场景下
    C# 内存占用排名 6 Go 排名 8 Java 排名 13
    Java 可真耗内存
    lolizeppelin
        38
    lolizeppelin  
       2022-06-27 14:46:48 +08:00
    erlang 居然只比 python2 好一点点?
    snoopyhai
        39
    snoopyhai  
       2022-06-27 14:52:30 +08:00
    印象中, deno 不是说因为 node 差, 才生出来的嘛. node 都在榜上, deno 上不了榜么?
    kerrspace
        40
    kerrspace  
       2022-06-27 15:08:25 +08:00
    @liuxu 哎 日了 早晚要开始学 rust ,我乍一看感觉曲线挺陡的
    Morii
        41
    Morii  
       2022-06-27 15:10:18 +08:00   ❤️ 3
    Go 其实没大家想的那么快,而且做 WEB 开发心智负担有点大,还是适合写一些基础设施、中间件
    zhangchongjie
        42
    zhangchongjie  
       2022-06-27 15:11:02 +08:00
    说 js 差的,这个数据有点打脸了😂,现在不是 php 是最好的语言,现在是 python
    DOLLOR
        43
    DOLLOR  
       2022-06-27 15:18:37 +08:00
    @buxudashi
    你说的那个是 LuaJIT ,类似于 PyPy 之于 Python ,性能跟 JS V8 相当。
    zhuangzhuang1988
        44
    zhuangzhuang1988  
       2022-06-27 15:19:13 +08:00   ❤️ 2
    C# 牛逼
    icyalala
        45
    icyalala  
       2022-06-27 15:32:59 +08:00   ❤️ 1
    @Leviathann @MakHoCheung
    Swift 的安全特性,很多都是默认开启放在运行时的。比如 a + b 实际运行时会添加额外指令来检测 overflow 。
    如果要考虑性能的话,至少要明白这点,比如 a + b 应该改为 a &+ b 来允许 overflow 。

    这个测试代码很多都没考虑这点:
    https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/swift.html
    Chad0000
        46
    Chad0000  
       2022-06-27 15:36:35 +08:00 via iPhone   ❤️ 3
    什么时候 C#打包的应用能和 Go 一样小就更 NB 了。

    利益相关:C#程序员
    cnoder
        47
    cnoder  
       2022-06-27 15:37:32 +08:00
    lua 应该没算 luajit 吧
    svt
        48
    svt  
       2022-06-27 15:41:01 +08:00
    开打开打
    lujiaosama
        49
    lujiaosama  
       2022-06-27 15:43:08 +08:00
    nodejs 还挺快, 问题是 nodejs 也算语言??
    wanacry
        50
    wanacry  
       2022-06-27 15:46:31 +08:00
    没 js 吗
    INCerry
        51
    INCerry  
       2022-06-27 15:50:19 +08:00   ❤️ 5
    @Chad0000 目前是可以做到, 有一个 reflection-free 选项,开启以后打包出来的只有几 MB
    但是需要放弃很多特性(比如反射会弱的一批,动态加载没了,EMIT 代码生成没办法了-基本上很多 AOP ORM 框架都用不了了),写起来就跟直接用 Go 差不多了,很不爽。
    https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/docs/reflection-free-mode.md
    ysc3839
        52
    ysc3839  
       2022-06-27 15:51:57 +08:00 via Android
    @MakHoCheung 编译成机器代码不代表中间运行时没有开销。比如 Objective-C 也是编译成机器代码的,但是对象间进行消息传递(类似别的语言的函数调用)要走 objc runtime 绕一圈,开销较大。
    @snoopyhai 是觉得 Node.js 设计得不好吧,而不是底层引擎性能差。
    @lujiaosama 准确说应该是 V8 引擎,除非这个测试涉及了网络部分。
    Building
        53
    Building  
       2022-06-27 16:00:29 +08:00
    Swift 已经沉浸在各类语法糖中无法自拔,在稳定性上用点心好吗?
    maclon
        54
    maclon  
       2022-06-27 16:09:36 +08:00
    rust 超屌
    cnnbboy
        55
    cnnbboy  
       2022-06-27 16:10:08 +08:00
    Swift 这么拉跨。。
    roundgis
        56
    roundgis  
       2022-06-27 16:18:41 +08:00 via Android   ❤️ 2
    @Phishion python 慢的基本上不是用 c 就是 cython 重寫了 所以實際上差距並不明顯

    如果涉及到和數據庫交互 差異就更小了
    gimp
        57
    gimp  
       2022-06-27 16:20:46 +08:00
    悲哉!我大 Python
    Features
        58
    Features  
       2022-06-27 16:31:46 +08:00
    实际上 99.99%的人都不会遇到语言上的瓶颈
    都是其他方面的
    后端基本是 I/O 的,前端是 webview ,浏览器环境调优
    客户端就海了去了,基本没有一个是语言本身带来的瓶颈
    qrobot
        59
    qrobot  
       2022-06-27 16:35:53 +08:00   ❤️ 1
    @Features 如果语言本身没有瓶颈 , 那么能解释一下 Discord 为什么要从 go 切换到 rust ?
    qrobot
        60
    qrobot  
       2022-06-27 16:36:42 +08:00
    @Features 能解释一下这篇文章里面说的信息吗?

    https://discord.com/blog/why-discord-is-switching-from-go-to-rust
    abersheeran
        61
    abersheeran  
       2022-06-27 16:49:18 +08:00   ❤️ 2
    @qrobot 显然 discord 的这个业务是那 1%,你可以尝试去调查一下,有多少人开发的业务需要精细化到扣 GC 时间。绝大部分的业务甚至连 Python 的瓶颈都摸不到。更别提 Golang 了。

    类似于 V2EX 甚至 Instagram 的 CRUD ,Python 就够用了。
    greygoo
        62
    greygoo  
       2022-06-27 16:49:45 +08:00
    看看好玩就行了,没有什么参考性,性能都是要代价的
    g190875565
        63
    g190875565  
       2022-06-27 16:51:45 +08:00
    jsnb
    qrobot
        64
    qrobot  
       2022-06-27 16:53:51 +08:00
    @abersheeran

    交换机, 路由器, 还有 arduino 设备。 也是其中的 1%吗? 还有 linux 内核 等等, 你这个 1% 确实有点多啊。。。。。
    qrobot
        65
    qrobot  
       2022-06-27 16:55:14 +08:00
    @abersheeran 在补充一下 chromium 如果也是 1% 那么你说的百分之一占据的全世界的开发还是挺多的
    abersheeran
        66
    abersheeran  
       2022-06-27 16:56:48 +08:00   ❤️ 1
    @qrobot 💦给你说个反直觉的东西,Web 服务,php 的占有率高达 78.9%。这世界上的程序远比你想象的多。
    abersheeran
        67
    abersheeran  
       2022-06-27 16:58:52 +08:00   ❤️ 1
    @qrobot chromium 既然你提到这个,那你思考一下,是在 chromium 上面跑页面的业务多,还是开发 chromium 的多。
    NeezerGu
        68
    NeezerGu  
       2022-06-27 16:59:25 +08:00
    如果这是跑分图,我大 python 秒天秒地 doge
    qrobot
        69
    qrobot  
       2022-06-27 17:00:06 +08:00
    @abersheeran 实际上开发 chromium ,或者基于 chromium 开发出来的程序,比你想想中的多的多
    NeezerGu
        70
    NeezerGu  
       2022-06-27 17:00:37 +08:00
    @ecnelises 我怎么记得 OCaml 速度应该比 haskell 快很多?不是常常用来写量化交易还是什么的吗?
    Protocol
        71
    Protocol  
       2022-06-27 17:01:23 +08:00
    明明 C++是第一,而且 C#比 C++性能表现已经低了一倍,为什么那么多喊 C#牛逼的却没有喊 C++牛逼的?
    abersheeran
        72
    abersheeran  
       2022-06-27 17:01:23 +08:00
    @qrobot 嗯,我最近的活刚好就是有一部分涉及到 chromium 。你说是网站多,还是开发 chromium 的多?
    qrobot
        73
    qrobot  
       2022-06-27 17:07:32 +08:00
    @abersheeran PHP 的占有率是百分之 78.9%, 这是原文,如果是这个去调查肯定不太准啊

    这个调查结果是来着这里的对吧 https://w3techs.com/technologies

    Methodology
    When interpreting our surveys, you should know the following:

    We investigate technologies of websites, not of individual web pages. If we find a technology on any of the pages, it is considered to be used by the website.
    We include only the top 10 million websites (top 1 million before June 2013) in the statistics in order to limit the impact of domain spammers. We include all sites that are either in the Alexa top 10 million or in the Tranco top 1 million list. Website popularity rankings are sometimes considered inaccurate for measuring website traffic, but we find that they serve our purpose of providing a representative sample of established sites very well. The Alexa service retired on May 2022, but the ranking API will be operational until December 2022. We keep using Alexa for the time being, and we are working on alternatives.
    We exclude sites that have no useful content, e.g. sites that only show the default web server page. We also exclude sites that are essentially duplicates of other sites.
    We do not include redirected domains. For example, Sun.com redirects to Oracle.com, and is therefore not counted.
    We do not consider subdomains to be separate websites. For instance, sub1.example.com and sub2.example.com are considered to belong to the same site as example.com. That means for example, that all the subdomains of blogger.com, wordpress.com and similar sites are counted only as one website.
    We use the official part of the Public Suffix List to determine what exactly is a website. Because this differs a bit from Alexa's and Tranco's definition, the "top 10 million" websites are actually not exactly 10 million. However, this has no statistical significance.
    Our reports are updated daily.
    Please be aware of the limitations indicated in our disclaimer.
    min
        74
    min  
       2022-06-27 17:08:49 +08:00
    @Protocol 玩不转 C++,不会用,性能再高也白搭
    qrobot
        75
    qrobot  
       2022-06-27 17:08:55 +08:00
    @abersheeran 开发 chromium 绝对不可能是只有 1%, 甚至开始说的 0.01% 是绝对不可能的
    Chad0000
        76
    Chad0000  
       2022-06-27 17:09:16 +08:00
    @INCerry
    哇,发现了新天地。不过这部分确实用不着。用 C#就是图语法好性能也高工作也好找(国外)。
    Chad0000
        77
    Chad0000  
       2022-06-27 17:10:38 +08:00
    @Protocol
    我觉得可能是因为不少国人对 C#还停留在.net framework 时代。
    qrobot
        78
    qrobot  
       2022-06-27 17:12:03 +08:00
    @Chad0000 C# 确实很不错, 但是害怕 microsoft 这家公司, 你不知道什么时候会和 IE 一样。
    di1012
        79
    di1012  
       2022-06-27 17:14:41 +08:00
    作为一个.netor 很欣慰
    Mithril
        80
    Mithril  
       2022-06-27 17:15:59 +08:00
    @Protocol 因为 C++牛逼这事不用喊,大家都知道。。。
    gbw1992
        81
    gbw1992  
       2022-06-27 17:18:13 +08:00
    同样解释性语言,nodejs 和 python 为啥差这么多
    zhangchongjie
        82
    zhangchongjie  
       2022-06-27 17:20:05 +08:00
    @Protocol 因为 v 站用的人太少了吧
    novolunt
        83
    novolunt  
       2022-06-27 17:21:25 +08:00
    @Phishion hhaahhaha
    INCerry
        84
    INCerry  
       2022-06-27 17:22:20 +08:00
    @Protocol 因为 C/C++一直都是天花板 但是 C# 开发效率高 另外是带 JIT GC Runtime 里面跑的最快的
    Mark24
        85
    Mark24  
       2022-06-27 17:23:38 +08:00
    @gbw1992 谷歌爸爸在 JavaScript V8 引擎里给 带了 JIT ,默认开启。
    Mark24
        86
    Mark24  
       2022-06-27 17:25:14 +08:00
    gbw1992
        87
    gbw1992  
       2022-06-27 17:28:16 +08:00
    @Protocol
    C++牛逼按说不需要喊吧,因为是爸爸
    就类似~大家都喊 c++牛逼为啥没人喊 c 牛逼~
    Mark24
        88
    Mark24  
       2022-06-27 17:38:06 +08:00
    86 楼的图,换了个图床

    hronro
        89
    hronro  
       2022-06-27 17:39:29 +08:00
    @buxudashi #19

    我记得他这个测试里用的是原版 Lua 而不是 LuaJIT
    cclin
        90
    cclin  
       2022-06-27 17:40:38 +08:00 via Android
    haskell 这么快我是没想到的
    andrew2558
        91
    andrew2558  
       2022-06-27 17:54:51 +08:00
    go 和 dart 这么差吗
    andrew2558
        92
    andrew2558  
       2022-06-27 17:56:20 +08:00
    dart 比 node.js 差是有点不理解
    tramm
        93
    tramm  
       2022-06-27 17:57:06 +08:00
    我记得 Java 性能能达到 C 的 70%左右的啊
    bbqqddwhy
        94
    bbqqddwhy  
       2022-06-27 17:58:15 +08:00
    引战贴,坏人啊
    aviator
        95
    aviator  
       2022-06-27 18:04:39 +08:00
    不知道 java 有没有用到后端编译的 JIT
    DOLLOR
        96
    DOLLOR  
       2022-06-27 18:06:40 +08:00
    @gbw1992 脚本语言开启 JIT 后,也会有编译过程,已经不完全算“解释执行”了。
    karatsuba
        97
    karatsuba  
       2022-06-27 18:13:29 +08:00
    C++ + Python 哈哈哈
    fgwmlhdkkkw
        98
    fgwmlhdkkkw  
       2022-06-27 18:18:47 +08:00
    @zhangchongjie #42 这是 v8 强,js 就是垃圾啊
    fgwmlhdkkkw
        99
    fgwmlhdkkkw  
       2022-06-27 18:19:56 +08:00
    @gbw1992 #81 v8 有 jit ,python 没有。
    GrayXu
        100
    GrayXu  
       2022-06-27 18:23:56 +08:00
    话说 benchmark 具体的测试项目应该也影响不小吧。。这图里 Go 居然和 Java 差不多速度。。
    1  2  
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   963 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 20:21 · PVG 04:21 · LAX 13:21 · JFK 16:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.