Created
March 18, 2016 15:32
-
-
Save anubisthejackle/a5dc887bedd82dd993b5 to your computer and use it in GitHub Desktop.
!empty($x) vs. $x
This file contains 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 | |
$a = null; | |
$start = microtime(true); | |
for($i = 0; $i < 1000000000; $i++){ | |
if( !empty( $a ) ){} | |
} | |
$empty = microtime(true) - $start; | |
$start = microtime(true); | |
for($i = 0; $i < 1000000000; $i++){ | |
if( $a ){} | |
} | |
$no_empty = microtime(true) - $start; | |
$difference = ($empty / $no_empty) * 100; | |
echo <<<HTML | |
########################## | |
Empty: $empty | |
No Empty: $no_empty | |
Percent Faster: $difference% | |
########################## | |
HTML; | |
/* | |
########################## | |
Empty: 45.424256086349 | |
No Empty: 31.626209974289 | |
Percent Faster: 143.62851610508% | |
########################## | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment