六安论坛网站,重庆家居网站制作公司,如何建设游戏网站,可编辑个人简历模板在对类执行100w次循环后#xff0c; 常量最快#xff0c;变量其次#xff0c;静态变量消耗时间最高 其中#xff1a; 常量消耗#xff1a;101.1739毫秒 变量消耗#xff1a;2039.7689毫秒 静态变量消耗#xff1a;4084.8911毫秒 测试代码#xff1a; class Timer_profi…在对类执行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 stylecolor: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($i0;$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($i0;$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($i0;$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; View Code 转载于:https://www.cnblogs.com/simon-sun/p/3412309.html