PHP 封装二维数组排序速度快,还是 MySQL order by 排序快? [ 2.0 版本 ]
PHP 封装二维数组排序速度快,还是 MySQL order by
排序快?
希望大家发表各自的意见,一起讨论一下
共 2 个回答
-
数据库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内置排序函数 > 自定义排序函数 -
PHP学院的中学生
注册时间:2018-10-23
最后登录:2025-03-24
在线时长:168小时46分
最后登录:2025-03-24
在线时长:168小时46分
- 粉丝29
- 金钱4730
- 威望30
- 积分6710