-
-
Save anonymous/f89d7e2da4ef262dea30e95fe7a30235 to your computer and use it in GitHub Desktop.
in_array strict comparison
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 | |
$bench = function(callable $code, $arg){ | |
$start = microtime(true); | |
$code($arg); | |
$end = microtime(true) - $start; | |
return $end; | |
}; | |
$needle = 128; | |
$testArray = ['2', '4', '8', '16', '32', '64']; | |
$test = function($strict) use ($testArray, $needle){ | |
for($i = 0; $i < 1 * 1000 * 1000; $i++){ | |
in_array($needle, $testArray, $strict); | |
} | |
}; | |
var_dump($bench($test, false)); | |
var_dump($bench($test, true)); | |
// float(0.33267593383789) | |
// float(0.061913013458252) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment