note 39790 added to language.operators.increment
| From: | jukkissh at hotmail dot com | Date: | Tue, 10 Feb 2004 18:54:29 +0000 |
| Subject: | note 39790 added to language.operators.increment | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-64976@lists.php.net to get a copy of this message | ||
As we all know, decrement is faster than increment ;)
Take this speed test script for example:
<?php
echo "<html><head><title>Speed
testing</title></head><body>";
$run_cycles = 1000000;
echo "\n<!--\n\n";
$pts = microtime(); # time calculation start-point
##################################
# one time executions
##################################
for ($lap = $run_cycles; $lap > 0; --$lap) {
##################################
# The actual test-cycle
##################################
} // for loop
##################################
list($use, $se) = explode(" ", microtime()); # time calculation end-point
list($uss, $ss) = explode(" ", $pts);
$pts = $uss + $ss;
$pte = $use + $se;
$pt = $pte - $pts;
echo "\n\n-->\n";
echo "\n\nProcessing time: " . substr($pt, 0, 7) . " seconds for " . $run_cycles
. " run cycles.";
echo "</body></html>";
?>
With my P2 350 MHz, Windows 2000, IIS webserver the empty loop got more than one second faster by
changing loop from adding to decreasing the counter $lap. Please notice 1 000 000 empty cycles :) I
want to develop a perfect speed testing script, if you can help me out with this one, please mail
me.
Also, as I'm a speed freak, if PHP could develop in a way, that you could speed up script
execution by declaring (at least some) variables fixed to some type, and win some speed there, it
would be very reasonable. I've noticed that using for example "(integer)" into some
statements can increase the speed greatly. But where is the documentation for this? When did this
feature come available? I found this out by axident when trying it "for fun" after I
learned it from C. I wonder if other speed tricks from C apply in PHP...
----
Manual Page -- http://www.php.net/manual/en/language.operators.increment.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39790
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39790&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39790&report=yes
Search -- http://master.php.net/manage/user-notes.php