最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php中用缓存与不用缓存性能测试
时间:2022-06-24 17:58:09 编辑:袖梨 来源:一聚教程网
在Thinkphp项目中测试各种环境下的程序执行时间
不使用缓存:
| 代码如下 | 复制代码 |
|
header("content-type:text/html;charset=utf-8"); $articles=array(); //循环取出500条文章信息 $overtime=caltime();//结束时间 echo '不使用缓存条件下程序执行时间是:'.($overtime-$starttime).'秒'; ?> |
|
结果:不使用缓存条件下程序执行时间是:0.0600001811981秒
文件缓存:
| 代码如下 | 复制代码 |
|
header("content-type:text/html;charset=utf-8"); $starttime=caltime();//开始时间 $articles=S('articles'); $overtime=caltime();//结束时间 echo '使用文件缓存条件下程序执行时间是:'.($overtime-$starttime).'秒'; |
|
结果:使用文件缓存条件下程序执行时间是:0.00999999046326秒
| 代码如下 | 复制代码 |
|
header("content-type:text/html;charset=utf-8"); $mem=new Memcache(); $articles=$mem->get('articles'); if(!$articles){ $overtime=caltime();//结束时间 echo '使用memcache缓存条件下程序执行时间是:'.($overtime-$starttime).'秒'; |
|
结果:使用memcache缓存条件下程序执行时间是:0.00999999046326秒
| 代码如下 | 复制代码 |
|
header("content-type:text/html;charset=utf-8"); $redis=new Redis(); if(!$redis){ $articles=$redis->get('articles'); if(!$articles){ $overtime=caltime();//结束时间 echo '使用redis缓存条件下程序执行时间是:'.($overtime-$starttime).'秒'; ?> |
|
结果:使用redis缓存条件下程序执行时间是:0.00999999046326秒
可见使用缓存的条件下,程序的执行速度比不使用缓存的时候快了6倍,
但是不同缓存由于数据不是特别庞大,几乎没有什么差别
相关文章
- mcjs网页版即点即玩-mcjs极速秒玩入口 10-23
- 超星学习通网页版登录-超星学习通官网入口 10-23
- poki免费游戏大全-poki免费游戏在线畅玩入口 10-23
- mc.js官方在线入口 10-23
- 海角haijiao社区2025全新网址一键直达-海角社区最新官方入口地址 10-23
- 王者荣耀世界体力上限与恢复方法详解 王者荣耀世界体力机制全面解析 10-20