note 105358 deleted from function.microtime by danbrown
| From: | danbrown@php.net | Date: | Thu, 11 Aug 2011 14:23:35 +0000 |
| Subject: | note 105358 deleted from function.microtime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-182429@lists.php.net to get a copy of this message | ||
Note Submitter: sukitsupaluk at hotmail dot com
----
<?php
define("LOOPCOUNT", 1000);
define("GRAP", 5);
define("TESTCOUNT", 15);
function benchmark($func,$out=TRUE){
static $first=TRUE; if($first){$first=FALSE;benchmark($func,FALSE);} //burn first process
if($out) echo $func,": <br/>";
$btime=array();
for($i=0;$i<TESTCOUNT;++$i) {
$time = microtime(TRUE);
for($x=0;$x< LOOPCOUNT;++$x){
$func();
}
$time=microtime(TRUE)-$time;
if($x > GRAP) {
$btime[]=$time;
if($out) echo substr($time,0,8)," ";
}
}
if($out) echo "Average: ", substr(array_sum($btime) / count($btime),0,5)
,"<br/><br/>";
}
function test(){
crc32("12345679");
}
function test2(){
crc32("1234567a");
}
benchmark("test");
benchmark("test2");
?>
output :
test:
0.003493 0.003639 0.003493 0.003482 0.003551 0.003499 0.003633 0.003554 0.003486 0.003478 0.003556
0.003491 0.003482 0.003468 0.003456 Average: 0.003
test2:
0.003620 0.003538 0.003540 0.003522 0.003520 0.003599 0.003489 0.003489 0.003509 0.003529 0.003596
0.003525 0.003520 0.003522 0.003617 Average: 0.003