Last active
August 29, 2015 14:15
-
-
Save e0ipso/11578357e02022df0c0e to your computer and use it in GitHub Desktop.
empty vs array_key_exists
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 | |
define('ITERATIONS', 10000000); | |
$array = array( | |
'foo' => 'bar', | |
'baz' => 'zzz', | |
); | |
for ($i = 0; $i < ITERATIONS; $i++) { | |
array_key_exists('foo', $array); | |
array_key_exists('invalid', $array); | |
} | |
print 'Finished' . PHP_EOL; |
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 | |
define('ITERATIONS', 10000000); | |
$array = array( | |
'foo' => 'bar', | |
'baz' => 'zzz', | |
); | |
for ($i = 0; $i < ITERATIONS; $i++) { | |
empty($array['foo']); | |
empty($array['invalid']); | |
} | |
print 'Finished' . PHP_EOL; |
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
----------------------------------------------------------------------- | |
⮀ time php array_key_exists.php | |
Finished | |
php array_key_exists.php 20.92s user 0.20s system 99% cpu 21.185 total | |
----------------------------------------------------------------------- | |
----------------------------------------------------------------------- | |
⮀ time php empty.php | |
Finished | |
php empty.php 2.90s user 0.03s system 98% cpu 2.982 total | |
----------------------------------------------------------------------- | |
----------------------------------------------------------------------- | |
⮀ time php empty.php | |
Finished | |
php empty.php 2.91s user 0.04s system 98% cpu 2.995 total | |
----------------------------------------------------------------------- | |
----------------------------------------------------------------------- | |
⮀ time php array_key_exists.php | |
Finished | |
php array_key_exists.php 19.22s user 0.17s system 99% cpu 19.460 total | |
----------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment