note 35261 added to function.strcmp
| From: | mike at mikeeheler dot ca | Date: | Mon, 25 Aug 2003 20:18:25 +0000 |
| Subject: | note 35261 added to function.strcmp | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-55062@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.strcmp.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35261
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35261&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35261&report=yes