note 27116 deleted from function.include by sniper
| From: | sniper@php.net | Date: | Sat, 18 Jan 2003 15:23:19 +0000 |
| Subject: | note 27116 deleted from function.include by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-42347@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