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']."
";
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;
}