2019-08-07 10:44:28 121次浏览 2条回答 0 悬赏 10 金钱

PHP 封装二维数组排序速度快,还是 MySQL order by 排序快?

希望大家发表各自的意见,一起讨论一下

亿速云
  • 回答于 2019-08-07 11:20 举报

    数据库1000条数据,300请求 200并发

    使用mysql排序(3次测试)
    Requests per second:    2106.74 [#/sec] (mean)
    Time per request:       94.933 [ms] (mean)
    Time per request:       0.475 [ms] (mean, across all concurrent requests)
    Transfer rate:          500.95 [Kbytes/sec] received
    
    
    Requests per second:    2149.77 [#/sec] (mean)
    Time per request:       93.033 [ms] (mean)
    Time per request:       0.465 [ms] (mean, across all concurrent requests)
    Transfer rate:          510.92 [Kbytes/sec] received
    
    Requests per second:    1953.02 [#/sec] (mean)
    Time per request:       102.405 [ms] (mean)
    Time per request:       0.512 [ms] (mean, across all concurrent requests)
    Transfer rate:          456.57 [Kbytes/sec] received
    
    使用rsort()排序(3次测试)
    Requests per second:    1885.29 [#/sec] (mean)
    Time per request:       106.085 [ms] (mean)
    Time per request:       0.530 [ms] (mean, across all concurrent requests)
    Transfer rate:          442.67 [Kbytes/sec] received
    
    Requests per second:    1885.29 [#/sec] (mean)
    Time per request:       106.085 [ms] (mean)
    Time per request:       0.530 [ms] (mean, across all concurrent requests)
    Transfer rate:          442.67 [Kbytes/sec] received
    
    
    Requests per second:    1940.47 [#/sec] (mean)
    Time per request:       103.068 [ms] (mean)
    Time per request:       0.515 [ms] (mean, across all concurrent requests)
    Transfer rate:          463.27 [Kbytes/sec] received
    

    从结果看,mysql order by 排序比PHP处理排序快,这里使用的是php内置函数rsort()都比mysql的排序慢了,如果自己封装一个排序操作函数,速度会更慢。
    所以结论: mysql order by 排序 > php内置排序函数 > 自定义排序函数

  • 回答于 2019-08-08 21:49 举报

    mysql直接排序,可以用在分页里,而php要做排序 ,要把全部数据拉出来才能做分页。
    所以实用性上,没有可比性

您需要登录后才可以回答。登录 | 立即注册
PHP学院的中学生
主管

PHP学院的中学生

注册时间:2018-10-23
最后登录:2天前
在线时长:28小时52分
  • 粉丝5
  • 金钱260
  • 威望10
  • 积分640

热门问题