想请大家帮忙跑一下这个 PHP 文件,看看我们设备差距有多少 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
请不要在回答技术问题时复制粘贴 AI 生成的内容
Features
V2EX    程序员

想请大家帮忙跑一下这个 PHP 文件,看看我们设备差距有多少

  •  2
     
  •   Features 2022-04-09 21:51:18 +08:00 7744 次点击
    这是一个创建于 1280 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我最近一直在看二手区,想更新 PC 主机
    刚好有个 V 友说写一亿个 IP 到文件中花费时间
    我刚好在学习 PHP ,就用 PHP 写了一个

    下载地址:
    http://175.178.215.195/ip.php

    电脑装了 PHP 的 V 友有空可以帮跑一下,看看时间是多少,这样我可以比较直观地看出我电脑和其他设备的差距
    我的总耗时大概是 6000 ms
    第 1 条附言    2022-04-10 02:27:24 +08:00
    http://175.178.215.195/ip.php 原文件
    http://175.178.215.195/ip2.php 根据 @secondwtq 把 implode 放入 calc 阶段,可以更清楚地计算出 IO 时间
    104 条回复    2022-04-15 18:54:36 +08:00
    1  2  
    deplivesb
        1
    deplivesb  
       2022-04-09 22:10:44 +08:00
    Kinnice
        2
    Kinnice  
       2022-04-09 22:28:10 +08:00
    calc time:5106.1282157898
    all time:8583.1022262573
    Features
        3
    Features  
    OP
       2022-04-09 22:28:49 +08:00
    @deplivesb 请问下什么配置?
    Features
        4
    Features  
    OP
       2022-04-09 22:29:04 +08:00
    @Kinnice 请问下什么配置?
    Kinnice
       
    Kinnice  
       2022-04-09 22:32:09 +08:00
    @Features aarch64 (64 Bit) /4 Cores +16G
    2Nfree
        6
    2Nfree  
       2022-04-09 22:41:29 +08:00
    calc time:2897.068977356
    all time:6620.0299263%

    arm64 7Cores 16G
    Jxnujason
        7
    Jxnujason  
       2022-04-09 22:46:51 +08:00
    Xusually
        8
    Xusually  
       2022-04-09 22:48:25 +08:00
    calc time:2439.4578933716
    all time:3922.2249984741

    MacbookPro 16 寸 M1 Max 32G 10+24
    casper13
        9
    casper13  
       2022-04-09 22:49:41 +08:00
    calc time:4346.0350036621
    all time:6829.5969963074
    i5-11320h/16g
    A01514035
        10
    A01514035  
       2022-04-09 22:51:23 +08:00
    calc time:4198.469877243
    all time:12756.875038147
    MacBook Pro (15-inch, 2019). 2.3 GHz 八核 Intel Core i9
    aloxaf
        11
    aloxaf  
       2022-04-09 22:51:59 +08:00
    你这只能测单线程性能,哪里直观了
    试了下 3970x 还没 i7-11800H 跑得高( 6500ms vs 4500ms )
    Features
        12
    Features  
    OP
       2022-04-09 22:52:20 +08:00
    看来这个程序测不出什么
    M1 MAX 都出来了,跟我差不多。。。
    Features
        13
    Features  
    OP
       2022-04-09 22:52:44 +08:00
    @aloxaf 是啊,看不出来什么东西。。。
    Jxnujason
        14
    Jxnujason  
       2022-04-09 22:53:20 +08:00
    还不如娱乐大师来的直观
    Features
        15
    Features  
    OP
       2022-04-09 22:53:39 +08:00
    跟 PHP 版本也有关系,我的 PHP 版本是 7.4
    大家的 PHP 版本可能稍微低一点
    Features
        16
    Features  
    OP
       2022-04-09 22:53:59 +08:00
    @Jxnujason 确实
    Xusually
        17
    Xusually  
       2022-04-09 22:54:25 +08:00
    @Features 你这个写入了 800 多 MB 的文本文件,不同的机器的 hdd/ssd 性能差异太大了,没什么可比性。
    calc 部分单线程也确实能比较的有限。
    chendy
        18
    chendy  
       2022-04-09 22:55:10 +08:00
    calc time: 2578.9999961853
    all time: 5930.1080703735

    m1 16G
    Xusually
        19
    Xusually  
       2022-04-09 22:55:10 +08:00
    @Features 我 M1 Max 用的 php 是 homebrew 的 8.1.4
    juzisang
        20
    juzisang  
       2022-04-09 22:57:00 +08:00
    calc time:2528.5968780518
    all time:4155.0738811493%

    M1Pro 10C32G
    Features
        21
    Features  
    OP
       2022-04-09 22:57:21 +08:00
    @Xusually
    @chendy
    M1 单核性能确实很牛,calc 时间比 i9/i5 少一半
    ec0
        22
    ec0  
       2022-04-09 22:58:40 +08:00   1
    这测试的是内存和硬盘吧,和 cpu 关系不大
    运行的时候 内存占用 98% 硬盘占用 100% ,系统卡死

    calc time:299848.28782082
    all time:610035.60996056
    Xusually
        23
    Xusually  
       2022-04-09 22:59:05 +08:00
    @Features 嗯,单核 M1 、M1 Pro 、M1 Max 都差不多,#8 #18 #20 正好凑齐了
    Features
        24
    Features  
    OP
       2022-04-09 22:59:40 +08:00
    @ec0 跟单核性能还是有点关系,你看上面的 M1 计算阶段时间都很少
    Xusually
        25
    Xusually  
       2022-04-09 22:59:53 +08:00
    @ec0 老哥你这个给我整笑了
    Jxnujason
        26
    Jxnujason  
       2022-04-09 23:00:51 +08:00
    @ec0 这个速度惊了
    Features
        27
    Features  
    OP
       2022-04-09 23:01:14 +08:00
    @Xusually可惜都是土豪设备,要是来个丐版的 m1 mini 和 mba m1 就好了
    Features
        28
    Features  
    OP
       2022-04-09 23:01:46 +08:00
    @ec0 这个差了一个数量级,啥设备啊?
    ec0
        29
    ec0  
       2022-04-09 23:04:37 +08:00
    @Features i3/4G/hdd
    duxiansen
        30
    duxiansen  
       2022-04-09 23:14:31 +08:00
    calc time:3997.4188804626
    all time:6382.8439712524
    PC:i7-9700k+32g

    calc time:2432.1401119232
    all time:4424.0410327911
    mbp:m1pro+16g
    Mac
        31
    Mac  
       2022-04-09 23:27:41 +08:00
    calc time:2747.8239536285
    all time:4360.5968952179
    12700KF DDR4 3200
    zhangjinghua
        32
    zhangjinghua  
       2022-04-09 23:38:08 +08:00
    嗯,根本跑不动,直接报错了
    Features
        33
    Features  
    OP
       2022-04-09 23:40:41 +08:00
    @Mac 看评测 12 代 i9 单核超过 m1 max ,看来属实
    Features
        34
    Features  
    OP
       2022-04-09 23:41:40 +08:00
    @zhangjinghua 可能内存太小了,调大一点 swap 应该可以跑
    要占用 4g 以上
    Mac
        35
    Mac  
       2022-04-09 23:44:47 +08:00
    @Features #33 刚关掉虚拟机和守望又跑了一遍

    E:\>php ip.php
    calc time:2548.1879711151
    all time:4161.6599559784
    Features
        36
    Features  
    OP
       2022-04-09 23:52:24 +08:00
    @Mac 心动了,一定要买 12 代酷睿
    zxw567
        37
    zxw567  
       2022-04-09 23:57:35 +08:00
    我感觉我这是个假的 12 代
    └ $ php .\ip.php
    calc time:3925.6041049957
    all time:6053.2119274139
    zxw567
        38
    zxw567  
       2022-04-09 23:58:20 +08:00
    @zxw567 #37 是移动端的问题吗? 12700H
    dcty
        39
    dcty  
       2022-04-10 00:00:33 +08:00
    @zxw567 #38
    不要慌,我的 12700k 也就是比你快一丢丢而已。
    calc time:3444.5588588715
    all time:5286.3628864288
    Features
        40
    Features  
    OP
       2022-04-10 00:04:24 +08:00
    @zxw567 正常,跟 SSD 和内存频率也有关系
    我的是 Mac mini 8+256
    Features
        41
    Features  
    OP
       2022-04-10 00:08:05 +08:00
    我自己的 dell 笔记本:
    i5 10210U 20g/512G ssd
    calc time:4852.4708747864
    all time:8502.7868747711
    Features
        42
    Features  
    OP
       2022-04-10 00:16:03 +08:00
    台式机 r5 2600 16G/320g SATA SSD
    calc time:117811.52701378
    all time:389669.60310936
    再也不买 AMD 了
    pcmid
        43
    pcmid  
       2022-04-10 00:21:03 +08:00
    calc time:3869.6520328522
    all time:5615.1371002197
    pcmid
        44
    pcmid  
       2022-04-10 00:21:54 +08:00
    @pcmid 5950x PHP 8.1.4 on archlinux
    secondwtq
        45
    secondwtq  
       2022-04-10 01:44:47 +08:00
    你这个把 array 的空间在一开始用 array_fill 就分配好可以快不少
    虽然这样还是要花上很长时间分配(很可能比后面的 loop 还长),可能是一堆 page fault 导致的。

    另外建议把 implode 和写入分开算时间,写入阶段在同样的机器上能差出一两秒
    Features
        46
    Features  
    OP
       2022-04-10 02:20:29 +08:00
    @secondwtq 现在已经占用超过 4G 以上内存了,array_fill 我没用过,不过应该也会占挺多吧?
    对哦,implode 应该也是需要一点时间
    secondwtq
        47
    secondwtq  
       2022-04-10 02:48:30 +08:00
    @Features 占用区别不大,implode 之前一共也就占 3G ,implode 又吃掉 2G
    lasfresas
        48
    lasfresas  
       2022-04-10 09:43:18 +08:00
    calc time:4531.6250324249 all time:7093.4460163116
    PHP 8.0.10
    cpu: AMD Ryzen 7 5800H
    0x20H
        49
    0x20H  
       2022-04-10 09:48:12 +08:00
    calc time:4588.6249542236
    all time:9924.3159294128

    MacBook Pro (16-inch, 2019). 2.6 GHz 六核 Intel Core i7
    nomedia
        50
    nomedia  
       2022-04-10 10:13:46 +08:00
    calc time:5838.8249874115
    write time:691.69592857361
    all time:6530.5600166321%

    I7 8700K 32G RAM PHP 8.0.17
    stormer
        51
    stormer  
       2022-04-10 10:23:53 +08:00
    calc time:7154.4790267944
    write time:935.92810630798
    all time:8090.8138751984


    i9-10980XE 128G RAM php 8.1.4
    lscho
        52
    lscho  
       2022-04-10 10:48:44 +08:00
    calc time:2640.949010849
    all time:4873.9960193634

    M1 Mac mini
    jfcherng
        53
    jfcherng  
       2022-04-10 11:00:14 +08:00
    @secondwtq #45 要搞 micro optimization 的... array_push($arr, $val) 改 $arr[] = $val; 少了 function call 就能快上不少,竟只在做件事情...
    C603H6r18Q1mSP9N
        54
    C603H6r18Q1mSP9N  
       2022-04-10 11:12:47 +08:00
    calc time:3922.7759838104
    all time:8289.7439002991%

    MacBook Pro (15-inch, 2018)
    2.2 GHz 六核 Intel Core i7
    16 GB 2400 MHz DDR4

    ============
    calc time:15584.703922272 all time:31058.578968048
    阿里云 8C16G
    MeetTheFuture
        55
    MeetTheFuture  
       2022-04-10 11:20:45 +08:00
    calc time:4998.4979629517
    all time:15482.745885849%

    MacBook Pro (13-inch, 2018, Four Thunderbolt 3 Ports)
    2.3 GHz 四核 Intel Core i5
    8 GB 2133 MHz LPDDR3
    iicoder
        56
    iicoder  
       2022-04-10 12:13:20 +08:00
    calc time:2362.5390529633
    all time:3840.1119709015

    M1MAX
    cha1
        57
    cha1  
       2022-04-10 12:35:21 +08:00
    CPU:i9-10850k

    开启 xdebug 扩展:
    calc time:60390.217065811

    关闭 xdebug 扩展:
    calc time:4967.4339294434

    去掉一些没用扩展测试准确一些。
    cha1
        58
    cha1  
       2022-04-10 12:42:06 +08:00
    php --no-php-ini ip.php

    -n --no-php-ini Ignore php.ini completely.

    忽略掉自定义的配置,会准确一些
    cha1
        59
    cha1  
       2022-04-10 12:49:24 +08:00
    #53
    @jfcherng

    改了快上很多。

    array_push($ipArr,$i);
    calc time:4966.3610458374

    $ipArr[] = $i;
    calc time:2275.9618759155
    Dart
        60
    Dart  
       2022-04-10 12:53:25 +08:00
    有病毒你们傻吗
    encro
        61
    encro  
       2022-04-10 13:01:21 +08:00
    只能利用单核!!
    毫无意义
    secondwtq
        62
    secondwtq  
       2022-04-10 13:04:16 +08:00   1
    @jfcherng 是,但是还是不如 array_fill 快
    qwq11
        63
    qwq11  
       2022-04-10 13:10:26 +08:00   1
    calc time:6886.6419792175
    write time:2112.0090484619
    all time:8998.97813797

    谢谢,从来没感觉自己电脑这么垃圾过
    Ryzen 7 3700X @ 3.6 GHz
    jfcherng
        64
    jfcherng  
       2022-04-10 13:13:31 +08:00
    @secondwtq #62 哈, array_fill 先 pre-allocate 再值更快
    Features
        65
    Features  
    OP
       2022-04-10 13:23:45 +08:00
    @Dart
    病毒的事怎么说?
    kingjpa
        66
    kingjpa  
       2022-04-10 14:32:55 +08:00
    4 代 i7 4790k + 24g 内存+php7.3
    calc time:6624.15599823 all time:21778.345108032
    看来 4 代宝刀未老啊
    hsfzxjy
        67
    hsfzxjy  
       2022-04-10 14:57:15 +08:00
    calc time:7752.4108886719
    write time:676.14006996155
    all time:8428.5979270935

    Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz 太拉了
    encro
        68
    encro  
       2022-04-10 15:04:45 +08:00
    $ipArr= range(0,$max) 不到 1S
    learningman
        69
    learningman  
       2022-04-10 15:45:01 +08:00
    calc time:32806.836128235
    all time:38877.583026886

    r7-4800H
    liuzhaowei55
        70
    liuzhaowei55  
       2022-04-10 15:56:19 +08:00
    calc time:9647.6719379425
    write time:495.3351020813
    all time:10151.386022568

    MBP 17 i7
    yahon
        71
    yahon  
       2022-04-10 16:01:23 +08:00
    calc time:5541.2330627441
    write time:750.66804885864
    all time:6292.5171852112
    处理器:12th Gen Intel(R) Core(TM) i5-12400 2.50 GHz
    yahon
        72
    yahon  
       2022-04-10 16:03:10 +08:00
    16G 内存
    PHP 7.4.26
    Features
        73
    Features  
    OP
       2022-04-10 16:06:39 +08:00
    @encro ip 是随机的 32 位 int
    Features
        74
    Features  
    OP
       2022-04-10 16:06:53 +08:00
    @encro 随机的
    Features
        75
    Features  
    OP
       2022-04-10 16:07:51 +08:00
    @kingjpa 毕竟当年的顶级旗舰,还带 K
    Features
        76
    Features  
    OP
       2022-04-10 16:10:02 +08:00
    其实这个程序还是有点用的,上面发的
    对有需要托管自有 PHP 服务器的人来说
    最好选用新款 Intel CPU ,这样 calc 时间会大大缩短
    yEhwG10ZJa83067x
        77
    yEhwG10ZJa83067x  
       2022-04-10 16:28:49 +08:00
    calc time:9163.7020111084
    write time:1329.2951583862
    all time:10493.273973465

    32G 内存 2400G cpu PHP 7.3.11
    dmitsc
        78
    dmitsc  
       2022-04-10 16:31:56 +08:00
    calc time:6131.1450004578 write time:104.05707359314 all time:6235.2271080017

    ARM......
    Rache1
        79
    Rache1  
       2022-04-10 16:36:53 +08:00
    放在 SN750 上面,888ms 就可以了。2700X + 32G 2666 频率的 D4 内存条。

    calc time:7894.1259384155

    write time:888.93294334412

    all time:8783.9229106903


    把 array_push 换成 [] 语法,calc 仅需要 5000ms.

    calc time:4968.6708450317
    write time:865.20195007324
    all time:5834.743976593

    如果使用 array_fill 提前分配,可以在上面的基础上再减少 300 ~ 500ms 。
    Lirika
        80
    Lirika  
       2022-04-10 16:54:36 +08:00
    calc time:2447.9248523712
    all time:4018.8958644867%

    m1 pro 14 丐版 cpu ,32G
    hervey0424
        81
    hervey0424  
       2022-04-10 16:59:03 +08:00
    calc time:4502.0608901978
    all time:11407.759904861
    jeffw
        82
    jeffw  
       2022-04-10 17:50:10 +08:00
    calc time:5466.1450386047
    all time:10025.525093079
    lxcForPHP
        83
    lxcForPHP  
       2022-04-10 18:37:30 +08:00
    calc time:3843.309879303
    all time:6367.2878742218
    AMD4800H 32G
    haoliang
        84
    haoliang  
       2022-04-10 18:49:08 +08:00
    generator, buffered io, mmap 一个都没用上,开篇就要求 8G 内存上限
    yannxia
        85
    yannxia  
       2022-04-10 18:53:31 +08:00
    calc time:3261.0790729523
    all time:5479.4991016388

    AMD Ryzen 9 5900x 64G
    skyfix
        86
    skyfix  
       2022-04-10 19:27:32 +08:00
    calc time:3939.5830631256 all time:6724.6930599213
    AMD 5800X,32G
    Steps
        87
    Steps  
       2022-04-10 19:44:12 +08:00
    calc time:5807.119846344
    write time:227.92196273804
    all time:6035.1519584656%

    Apple M1 Pro
    muhuan
        88
    muhuan  
       2022-04-10 20:23:19 +08:00
    calc time:5107.4190139771
    all time:11993.241071701

    MacMini 2020 i7
    hope4tomorrow
        89
    hope4tomorrow  
       2022-04-10 20:54:51 +08:00
    calc time:5888.8449668884
    all time:8813.6730194092

    CPU aarch64 24G 内存 150G 机械硬盘
    Hurriance
        90
    Hurriance  
       2022-04-10 21:56:58 +08:00
    calc time:11680.121183395
    write time:1007.7757835388
    all time:12688.145160675%
    Hurriance
        91
    Hurriance  
       2022-04-10 21:57:37 +08:00
    MacBook Pro (Retina, 15-inch, Mid 2015)
    Hurriance
        92
    Hurriance  
       2022-04-10 21:58:18 +08:00
    2.2 GHz 四核 Intel Core i7 (不小心直接回复出去了 :D )
    EliStone
        93
    EliStone  
       2022-04-10 22:41:56 +08:00
    @zxw567 请问您的移动端是哪台设备呀,最近也想买电脑,但是苦于没有 32g 版本的
    cwcc
        94
    cwcc  
       2022-04-11 01:46:54 +08:00
    2020 年中的 13 寸 intel MBP ( 16G 10gen-i5 )
    calc time:4708.4519863129
    all time:10341.204881668

    AMD Ryzen 5600G ,用 Hyper-V 装的 Ubuntu
    calc time:3392.725944519
    all time:5450.3109455109
    cwcc
        95
    cwcc  
       2022-04-11 01:48:40 +08:00
    ip2 的测试:
    cwcc
        96
    cwcc  
       2022-04-11 01:49:03 +08:00
    AMD:
    calc time:5046.4730262756
    write time:665.90309143066
    all time:5712.4609947205

    mbp:
    calc time:9904.6189785004
    write time:334.36608314514
    all time:10239.08996582
    cwcc
        97
    cwcc  
       2022-04-11 01:50:27 +08:00
    上面数据反应的我两台电脑性能差距确实很接近,mbp 硬盘更强,amd 的 CPU 更强,但是多核还是没法测到。
    Ch3n4y
        98
    Ch3n4y  
       2022-04-11 09:29:48 +08:00
    M1 MAX 32G.

    calc time:2448.1270313263.

    all time:3989.186048507.
    Magician
        99
    Magician  
       2022-04-11 09:47:36 +08:00
    calc time:19949.950933456
    all time:30688.013076782

    macbookpro 2015
    FakerLeung
        100
    FakerLeung  
       2022-04-11 09:48:16 +08:00
    I7 8700, 32G

    ip.php
    calc time:3781.6679477692
    all time:24138.736009598

    ip2.php
    calc time:6127.002954483
    write time:17389.429092407
    all time:23516.4539814
    1  2  
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     961 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 32ms UTC 19:18 PVG 03:18 LAX 12:18 JFK 15:18
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86