1

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."\n";
echo 'inFunction='.$GLOBALS['totalTimeFunction']."\n";

在线代码

为什么outFunction大于inFunction?

为什么outFunction不等于inFunction?

在我的真实函数中,我连接到数据库并进行许多计算...... inFunction 和 outFunction 之间的时间差是 10 秒?(ajax 的时间线大约等于 outFunction 时间)

编辑 我的真实函数(表格内容有 100,000 条记录,我调用它 100 次,inFunction 和 outFunction 之间的差异是 10 秒)

 $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;          

}
4

0 回答 0