note 99915 added to control-structures.if

From: Date: Tue, 14 Sep 2010 20:14:09 +0000
Subject: note 99915 added to control-structures.if
Groups: php.notes 
Request: Send a blank email to php-notes+get-172563@lists.php.net to get a copy of this message
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 ---- Server IP: 217.160.235.204 Probable Submitter: 80.129.206.49 ---- Manual Page -- http://www.php.net/manual/en/control-structures.if.php Edit -- https://master.php.net/note/edit/99915 Del: integrated -- https://master.php.net/note/delete/99915/integrated Del: useless -- https://master.php.net/note/delete/99915/useless Del: bad code -- https://master.php.net/note/delete/99915/bad+code Del: spam -- https://master.php.net/note/delete/99915/spam Del: non-english -- https://master.php.net/note/delete/99915/non-english Del: in docs -- https://master.php.net/note/delete/99915/in+docs Del: other reasons-- https://master.php.net/note/delete/99915 Reject -- https://master.php.net/note/reject/99915 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#172563) next »