Hello,
Thanks for posting the benchmark class....
I have added some error checking in it. Because when people will use this with large amount of code they might get some errors.
/* *********************************************** */
<?php
/*Author: David Constantine Kurushin
zend.com/en/store/education/certifi
...
*/
Class Benchmark{
public static $stime=NULL,$etime=NULL;
public static function getm(){
return array_sum(explode(" ",microtime()));
}
public static function st(){//Benchmark::st();
self::$stime = self::getm();
self::$etime = NULL;
}
public static function et(){//Benchmark::et();
if( self::$stime != NULL )
self::$etime = self::getm();
else
echo "Set the start time first!!";
}
public static function result($round=10){//echo Benchmark::result(5);
if( self::$stime != NULL && self::$etime != NULL )
return number_format( (self::$etime - self::$stime) , $round, '.', '');
else
echo "One of the start or end time is not set!!";
}
public static function help(){//Benchmark::help();
echo "
<u><b>Methods list of Benchmark class</b></u><br/>
<b>static function getm();</b><br/>Returns current micro time <br/>
<b>public function st();</b><br/>Starts the timer<br/>
<b>public function et();</b><br/>Stops the timer<br/>
<b>public function result(\$round=10);</b><br/>
Show result, round means how much numbers after dot '.'<br/>
";
}
}
Benchmark::st();
Benchmark::et();
echo " <b>" . Benchmark::result(5) . "</b> sec. ";
// Wrong ways
// 1.
Benchmark::et(); //Set the start time first!!
// 2.
Benchmark::st();
echo " <b>" . Benchmark::result(5) . "</b> sec. "; //One of the start or end time is not set!!
?>
/* ******************************************************** */