Created
August 9, 2012 21:27
-
-
Save cebe/3308196 to your computer and use it in GitHub Desktop.
PHP empty($x) vs. $x===''
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $t = microtime(true); | |
| for($n=0; $n<10000000; $n++) { | |
| if (empty($class)) { | |
| } | |
| } | |
| $e = microtime(true) - $t; | |
| echo $e . "\n"; | |
| $class=''; | |
| $t = microtime(true); | |
| for($n=0; $n<10000000; $n++) { | |
| if ($class==='') { | |
| } | |
| } | |
| $e = microtime(true) - $t; | |
| echo $e . "\n"; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Actual result is that empty is slightly faster plus allows me to have $class variable undefined.