Skip to content

Instantly share code, notes, and snippets.

@shoemoney
Forked from robertuniqid/sample.php
Created January 24, 2022 11:50
Show Gist options
  • Save shoemoney/09e4e9b112d880bd800aa8748bf0cc07 to your computer and use it in GitHub Desktop.
Save shoemoney/09e4e9b112d880bd800aa8748bf0cc07 to your computer and use it in GitHub Desktop.
PHP : empty vs == vs ===
<?php
$t = '';
$before = microtime(true);
for ($i=0 ; $i<100000 ; $i++) {
$dummy = empty( $t );
}
$after = microtime(true);
echo 'empty : ' . ( $after - $before );
echo "\n";
$before = microtime(true);
for ($i=0 ; $i<100000 ; $i++) {
$dummy = $t == '';
}
$after = microtime(true);
echo '== "" : ' . ( $after - $before );
echo "\n";
$before = microtime(true);
for ($i=0 ; $i<100000 ; $i++) {
$dummy = $t === '';
}
$after = microtime(true);
echo '=== "" : ' . ( $after - $before );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment