, , func_get_args func_num_args, ...
php -v:
PHP 5.3.10-1ubuntu3.2 with Suhosin-Patch (cli) (built: Jun 13 2012 17:20:55)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
Output:
php dynFuncArgListTest.php
$StatTestTot: 14.194619178772
$DynTestTot: 33.246332645416
:
<?php
define('NEWLINE', "\n");
$StatTestTot = 0;
$DynTestTot = 0;
for($i = 0; $i < 9000; ++$i) {
$randBoolArr = CreateArrayWithRandomBoolValues(900);
$StatTestTot += StatTest($randBoolArr);
$DynTestTot += DynTest($randBoolArr);
$StatTestTot += StatTest($randBoolArr);
$DynTestTot += DynTest($randBoolArr);
$StatTestTot += StatTest($randBoolArr);
$DynTestTot += DynTest($randBoolArr);
$StatTestTot += StatTest($randBoolArr);
$DynTestTot += DynTest($randBoolArr);
}
echo '$StatTestTot: ' . $StatTestTot . NEWLINE;
echo '$DynTestTot: ' . $DynTestTot . NEWLINE;
function DynTest($randBoolArr) {
$StartDynTest = GetMicrotimeTrue();
foreach($randBoolArr as $aBool) {
IsBoolAndTrueDyn($aBool);
}
$EndDynTest = GetMicrotimeTrue();
$Dyndisplacement = $EndDynTest - $StartDynTest;
return $Dyndisplacement;
}
function StatTest($randBoolArr) {
$StartStatTest = GetMicrotimeTrue();
foreach($randBoolArr as $aBool) {
IsBoolAndTrue($aBool);
}
$EndStatTest = GetMicrotimeTrue();
$Statdisplacement = $EndStatTest - $StartStatTest;
return $Statdisplacement;
}
function GetMicrotimeTrue() { return microtime(true); }
function CreateArrayWithRandomBoolValues($size) {
$output = array();
for($i = 0; $i < $size; ++$i) {
$output[$i] = (rand(0, 1) === 0);
}
return $output;
}
function IsBoolAndTrue($input) {
if(!is_bool($input) || $input !== true) {
return false;
}
return true;
}
function IsBoolAndTrueDyn() {
$num_args = func_num_args();
if($num_args > 0) {
$args = func_get_args();
foreach($args as $arg) {
if(!is_bool($arg) || $arg !== true) {
return false;
}
}
return true;
}
return false;
}
?>