note 35261 deleted from function.strcmp by vincent
| From: | vincent@php.net | Date: | Tue, 26 Aug 2003 09:49:46 +0000 |
| Subject: | note 35261 deleted from function.strcmp by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-55089@lists.php.net to get a copy of this message | ||
Note Submitter: mike@mikeeheler.ca
----
Not sure where you get the 60% number from. I did a test.. first the vars:
$var = array('hello', 'world', 'hello');
Then I executed the following code 10 million times in a loop:
// not equal. returns true.
if (strcmp($var[0], $var[1])) $true++;
// equal, returns false
if (!strcmp($var[0], $var[2])) $false++;
And kept track of its execution time, then executed the following code 10 million times:
// not equal
if ($var[0] != $var[1]) $true++;
// equal
if ($var[0] == $var[2]) $false++;
I ran the test a couple dozen times, and every time the difference in execution time was within 5%,
usually around 4%. Using != and == was faster, but not by that crazy 60% number. I still advise
using != and == isntead of strcmp for if() statements because strcmp's logic is backward for
that kind of implementation.