doulun1939 2015-05-24 13:05
浏览 27

测量功能的执行时间

PHP

$totalTimeFunction=0;
function f1()
{
     $t1=microtime(true);
    for($i=0;$i<900;$i++)
    {}
    $t2=microtime(true);
    $p=($t2-$t1);
    $GLOBALS['totalTimeFunction']+=$p;  
}


 $t1=microtime(true);
f1();
$t2=microtime(true);
$p=($t2-$t1);
echo 'OutFunction='.$p."
";
echo 'inFunction='.$GLOBALS['totalTimeFunction']."
";

Online Code

why outFunction is greater than inFunction?

Why outFunction is not equal to inFunction?

In my real function i connect to database and do many calculations and ... the time difference between inFunction and outFunction is 10 second?(timeline for ajax is about equals to outFunction time)

Edit My real function (table content has 100,000 record and i call it 100 times,difference between inFunction and outFunction is 10 second)

 $contentTable=array();
function getNameTask($id)
{ 
     $t=microtime(true);


    if(empty($GLOBALS['contentTable']))
    {       
        $baseClass = new MsDatabase();   
        $query = "select CON_VALUE,CON_ID,CON_CATEGORY from content where CON_LANG='fa' and (CON_CATEGORY='TAS_TITLE' or CON_CATEGORY='PRO_TITLE' )";

        $GLOBALS['contentTable']= $baseClass->query($query,WF_WORKFLOW_DB_NAME_MARKAZE);            
    }

    foreach($GLOBALS['contentTable'] as $R)
    {

        if(trim($R['CON_ID'])==trim($id) && $R['CON_VALUE']!='' && trim($R['CON_CATEGORY'])=='TAS_TITLE' ){
            $t2=microtime(true);
             $p=($t2-$t);
            $GLOBALS['tt']+=$p;  
             return $R["CON_VALUE"];
        }
    }

     return 0;          

}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探