首页
4K壁纸
直播
统计分析
友情链接
搜索
1
#1031 – TABLE STORAGE ENGINE FOR ” DOESN’T HAVE THIS OPTION解决方法
1,112 阅读
2
让浏览器不显示 https 页面中 http 请求警报 http-equiv=”Content-Security-Policy” content=”upgrade-insecure-requests”
845 阅读
3
报错代码:ERROR 1227 (42000)-解决办法
639 阅读
4
微信个人商户号养号建议
528 阅读
5
解决移动端position:fixed随软键盘移动的问题
479 阅读
PHP
Mysql
Linux
Reids
Java
常用笔记
学习
乱七八糟
Search
标签搜索
php
千卡云支付
Mysql
Linux
redis
千卡云
千卡易支付
Nginx
shell
JS
JSON
支付宝
CentOS
Apache
支付
function
database
fastadmin
phpstorm
快捷键
蓝科迪梦
累计撰写
69
篇文章
累计收到
0
条评论
首页
栏目
PHP
Mysql
Linux
Reids
Java
常用笔记
学习
乱七八糟
页面
4K壁纸
直播
统计分析
友情链接
搜索到
1
篇与
的结果
2023-08-01
php 类静态变量 和 常量消耗内存及时间对比
在对类执行100w次循环后, 常量最快,变量其次,静态变量消耗时间最高 其中: 常量消耗:101.1739毫秒 变量消耗:2039.7689毫秒 静态变量消耗:4084.8911毫秒 class Timer_profiler { public static $begin_timer; public static $finish_timer; public static $timer_html; /** * 计算时间差 * @return type */ public static function getRecordTimer() { return (self::getFinishTimer() - self::getBeginTimer()) * 1000; } /** * 生成输出HTML * @param type $message * @return type */ public static function recordHtml($message = '') { self::setFinishTimer(); return "<p>{$message}耗时: " . self::getRecordTimer() . " 毫秒</p>"; } /** * 设置开始时间 */ public static function setBeginTimer() { self::$begin_timer = self::getTime(); } /** * 设置结束时间 */ public static function setFinishTimer() { self::$finish_timer = self::getTime(); } /** * 获取开始时间 * @return type */ public static function getBeginTimer() { return self::$begin_timer; } /** * 获取结束时间 * @return type */ public static function getFinishTimer() { return self::$finish_timer; } /** * 获取带微妙的时间戳 * @return type */ private static function getTime() { list($usec, $sec) = explode(" ", microtime()); return (number_format($sec+$usec,6,'.', '')); } } function computeTime($otime,$message){ return; $ntime = xdebug_time_index(); $str = ''; $str .= $message . ($ntime*1000-$otime*1000); $str .= "<br>"; echo $str; } function getMemoryUsed(){ $str = '消耗内存<h3 style="color:red"> '; $str .= round(memory_get_usage()/1024/1024, 4).'MB'; $str .= '</h3>'; echo $str; } $count_i = 100*10000; //$count_i = 100000; Timer_profiler::setBeginTimer(); computeTime(xdebug_time_index(),'开始执行'); echo Timer_profiler::recordHtml('开始执行'); getMemoryUsed(); class TestVar { public $A1 = 'aaaaaaaaaaaaaaaaa'; public $A2 = 'aaaaaaaaaaaaaaaaa'; public $A3 = 'aaaaaaaaaaaaaaaaa'; public $A4 = 'aaaaaaaaaaaaaaaaa'; public $A5 = 'aaaaaaaaaaaaaaaaa'; public $A6 = 'aaaaaaaaaaaaaaaaa'; public $A7 = 'aaaaaaaaaaaaaaaaa'; public $A8 = 'aaaaaaaaaaaaaaaaa'; } $TestVar = new TestVar(); for($i=0;$i<=$count_i;$i++){ $t = $TestVar->A1; $t = $TestVar->A2; $t = $TestVar->A3; $t = $TestVar->A4; $t = $TestVar->A5; $t = $TestVar->A6; $t = $TestVar->A7; $t = $TestVar->A8; } getMemoryUsed(); echo Timer_profiler::recordHtml('变量完成'); computeTime(xdebug_time_index(),'变量完成'); Timer_profiler::setBeginTimer(); class TestStaticVar { static $A1 = 'aaaaaaaaaaaaaaaaa'; static $A2 = 'aaaaaaaaaaaaaaaaa'; static $A3 = 'aaaaaaaaaaaaaaaaa'; static $A4 = 'aaaaaaaaaaaaaaaaa'; static $A5 = 'aaaaaaaaaaaaaaaaa'; static $A6 = 'aaaaaaaaaaaaaaaaa'; static $A7 = 'aaaaaaaaaaaaaaaaa'; static $A8 = 'aaaaaaaaaaaaaaaaa'; } for($i=0;$i<=$count_i;$i++){ $t = TestStaticVar::$A1; $t = TestStaticVar::$A2; $t = TestStaticVar::$A3; $t = TestStaticVar::$A4; $t = TestStaticVar::$A5; $t = TestStaticVar::$A6; $t = TestStaticVar::$A7; $t = TestStaticVar::$A8; } getMemoryUsed(); echo Timer_profiler::recordHtml('静态变量完成'); computeTime(xdebug_time_index(),'静态变量完成'); Timer_profiler::setBeginTimer(); class TestConstVar { const A1 = 'aaaaaaaaaaaaaaaaa'; const A2 = 'aaaaaaaaaaaaaaaaa'; const A3 = 'aaaaaaaaaaaaaaaaa'; const A4 = 'aaaaaaaaaaaaaaaaa'; const A5 = 'aaaaaaaaaaaaaaaaa'; const A6 = 'aaaaaaaaaaaaaaaaa'; const A7 = 'aaaaaaaaaaaaaaaaa'; const A8 = 'aaaaaaaaaaaaaaaaa'; } for($i=0;$i<=$count_i;$i++){ $t = TestConstVar::A1; $t = TestConstVar::A2; $t = TestConstVar::A3; $t = TestConstVar::A4; $t = TestConstVar::A5; $t = TestConstVar::A6; $t = TestConstVar::A7; $t = TestConstVar::A8; } getMemoryUsed(); echo Timer_profiler::recordHtml('常量完成'); computeTime(xdebug_time_index(),'常量完成'); //echo Timer_profiler::recordHtml('共执行'); computeTime(xdebug_time_index(),'共执行'); exit;
2023年08月01日
201 阅读
0 评论
0 点赞