21,893
社区成员
发帖
与我相关
我的任务
分享
t::start();t::end(); //消除t类首次加载的影响
t::start();
model_profile_base::getBaseInfo($uid);
t::end();
t::start();
$model = new model_profile_base();
$model->getBaseInfo($uid);
t::end();
<?php
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
class t{
static $start_time;
static $end_time;
static $start_memory;
static $end_memory;
public static function start()
{
self::$start_memory = memory_get_usage();
self::$start_time = microtime_float();
echo '<br/>Start @'.self::$start_time.'('.self::$start_memory.')|------->';
}
public static function end()
{
self::$end_time = microtime_float();
self::$end_memory = memory_get_usage();
echo 'End @'.self::$end_time.'('.self::$end_memory.') :';
echo '|======= 共耗时:'.(self::$end_time-self::$start_time).',共用内存:'.(self::$end_memory-self::$start_memory);
}
}
Start @1287561987.1805(1008368)|------->End @1287561987.1806(1008368) :|======= 共耗时:3.2901763916016E-5,共用内存:0
Start @1287561987.1806(1008368)|------->End @1287561987.1938(1586452) :|======= 共耗时:0.013248920440674,共用内存:578084
Start @1287561987.1938(1586452)|------->End @1287561987.1945(1586652) :|======= 共耗时:0.00065183639526367,共用内存:200
t::start();t::end(); //消除t类首次加载的影响
t::start();
for($i=0; $i<1000;++$i) model_profile_base::getBaseInfo($uid);
t::end();
t::start();
$model = new model_profile_base();
for($i=0; $i<1000;++$i) $model->getBaseInfo($uid);
t::end();
Start @1287562243.5799(1009372)|------->End @1287562243.5799(1009372) :|======= 共耗时:3.0040740966797E-5,共用内存:0
Start @1287562243.58(1009372)|------->End @1287562244.1532(1587544) :|======= 共耗时:0.57321000099182,共用内存:578172
Start @1287562244.1532(1587544)|------->End @1287562244.6921(1587744) :|======= 共耗时:0.53887605667114,共用内存:200
============Which method========================Time======
Inline calculation 0.0805 s
Normal function call 0.3438 s
Normal method called through object 0.4118 s
Static method called statically 0.4280 s
Unspecified method called through object() 0.4294 s
Unspecified method called statically() 0.6960 s