Skip to content

Instantly share code, notes, and snippets.

Created Mar 28, 2017
Embed
What would you like to do?
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