note 27116 added to function.include
| From: | RNova at no-spam-pleasegmx dot net | Date: | Sat, 23 Nov 2002 10:40:23 +0000 |
| Subject: | note 27116 added to function.include | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-39891@lists.php.net to get a copy of this message | ||
PERFORMANCE CONSIDERATION:
Included code is invoked much slower than normal in-line code (at least with PHP 4.2.3). In the
following example, the invocation took 7.3 secs on my computer, while the actual execution happens
in almost no time:
file Test.INC:
<?php
$n = $s{++$i};
++$c;
if(ord($n)==ord("a"))
--$c;
?>
file Test.PHP
<?php
function microtime_diff($a,$b) {
// thanks to mdchaney at michaelchaney dot com
list($a_micro, $a_int)=explode(' ',$a);
list($b_micro, $b_int)=explode(' ',$b);
if ($a_int>$b_int) {
return ($a_int-$b_int)+($a_micro-$b_micro);
} elseif ($a_int==$b_int) {
if ($a_micro>$b_micro) {
return ($a_int-$b_int)+($a_micro-$b_micro);
} elseif ($a_micro<$b_micro) {
return ($b_int-$a_int)+($b_micro-$a_micro);
} else {
return 0;
}
} else { // $a_int<$b_int
return ($b_int-$a_int)+($b_micro-$a_micro);
}
}
// create some long test string
$s="abcde";
while( strlen($s) < 10000 ) $s .= $s;
$c=0; $slen= strlen($s);
$start1 = microtime();
while($i < $slen) {
include('test.INC');
}
echo "time elapsed with include:".microtime_diff(
$start1,microtime())."<BR>\n";
$start2 = microtime();
while($i < $slen) {
// do the same thing in-line
$n = $s{++$i};
++$c;
if(ord($n)==ord("a"))
--$c;
}
echo "time elapsed without include:".microtime_diff(
$start2,microtime())."<BR>\n";
?>
output:
time elapsed with include:7.26901
time elapsed without include:5E-005
--
http://www.php.net/manual/en/function.include.php
http://master.php.net/manage/user-notes.php?action=edit+27116
http://master.php.net/manage/user-notes.php?action=delete+27116
http://master.php.net/manage/user-notes.php?action=reject+27116