note 99915 deleted from control-structures.if by cmb
| From: | cmb@php.net | Date: | Fri, 02 Oct 2020 12:26:17 +0000 |
| Subject: | note 99915 deleted from control-structures.if by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215516@lists.php.net to get a copy of this message | ||
Note Submitter: Rudi
----
Note that safe type checking (using === and !== instead of == and !=) is in general somewhat faster.
When you're using non-safe type checking and a conversion is really needed for checking, safe
type checking is considerably faster.
===================================
Test (100,000,000 runs):
<?php
$start = microtime(true);
for($i = 0; $i < 100000000; $i++)
if(5 == 10) {}
$end = microtime(true);
echo "1: ".($end - $start)."<br />\n";
unset($start, $end);
$start = microtime(true);
for($i = 0; $i < 100000000; $i++)
if('foobar' == 10) {}
$end = microtime(true);
echo "2: ".($end - $start)."<br />\n";
unset($start, $end);
$start = microtime(true);
for($i = 0; $i < 100000000; $i++)
if(5 === 10) {}
$end = microtime(true);
echo "3: ".($end - $start)."<br />\n";
unset($start, $end);
$start = microtime(true);
for($i = 0; $i < 100000000; $i++)
if('foobar' === 10) {}
$end = microtime(true);
echo "4: ".($end - $start)."<br />\n";
unset($start, $end);
?>
===================================
Result (depending on hardware configuration):
1: 16.779544115067
2: 21.305675029755
3: 16.345532178879
4: 15.991420030594