note 39671 added to language.operators.increment
| From: | chris at free-source dot com | Date: | Fri, 06 Feb 2004 21:11:46 +0000 |
| Subject: | note 39671 added to language.operators.increment | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-64743@lists.php.net to get a copy of this message | ||
Interesting performance note:
$i++ seems to be slightly slower than ++$i, when used on a line by itself the 2 have the same
purpose. It's not much, but over 100,000 incements the pre-increment is about .004 seconds
faster on average.
<?
$start = 0;
$stop = 0;
$post = array();
$pre = array();
function perfgetmicrotime()
{
list($usec, $sec) = explode(' ',microtime());
return ((float)$usec + (float)$sec);
}
//preload the variable to allocate the memory so the test will be fair for both
$i = 0;
while ($i < 100000)
{
$i++;
}
//start post test
for($j = 0 ; $j < 100 ; $j++)
{
$i = 0;
$start = perfgetmicrotime();
while ($i < 100000)
{
$i++;
}
$stop = perfgetmicrotime();
$post[] = $stop - $start;
}
echo "Post average: ".(array_sum($post)/count($post))."\n";
//start pre test
for($j = 0 ; $j < 100 ; $j++)
{
$i = 0;
$start = perfgetmicrotime();
while ($i < 100000)
{
++$i;
}
$stop = perfgetmicrotime();
$pre[] = $stop - $start;
}
echo "Pre average: ".(array_sum($pre)/count($pre))."\n";
?>
----
Manual Page -- http://www.php.net/manual/en/language.operators.increment.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39671
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39671&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39671&report=yes
Search -- http://master.php.net/manage/user-notes.php