Skip to content

Instantly share code, notes, and snippets.

Created March 28, 2017 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/f89d7e2da4ef262dea30e95fe7a30235 to your computer and use it in GitHub Desktop.
Save anonymous/f89d7e2da4ef262dea30e95fe7a30235 to your computer and use it in GitHub Desktop.
in_array strict comparison
<?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