Created
October 16, 2019 16:31
-
-
Save notian/220b2d9908eb0e48bec8bc0b08c8a953 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
for( $i = 0; $i < 1000000; $i++ ) | |
{ | |
$el[] = md5('XX-'.$i); | |
} | |
$start = microtime(true); | |
foreach( $el as $hash ) | |
{ | |
if( strpos($hash, 'a') === 0 ) | |
$aFinal[] = 'FOUND! '.$hash; | |
} | |
$time1 = microtime(true) - $start; | |
$start = microtime(true); | |
$bFinal = array_map(function($hash){ | |
return 'FOUND! '.$hash; | |
},array_filter($el, function($hash){ | |
return ( strpos($hash, 'a') === 0 ); | |
})); | |
$time2 = microtime(true) - $start; | |
echo count($aFinal).' took '.round($time1,4)."\n"; | |
echo count($bFinal).' took '.round($time2,4)."\n"; | |
?> | |
---- | |
62546 took 0.8741 | |
62546 took 2.2139 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment