Skip to content

Instantly share code, notes, and snippets.

@notian
Created October 16, 2019 16:31
Show Gist options
  • Save notian/220b2d9908eb0e48bec8bc0b08c8a953 to your computer and use it in GitHub Desktop.
Save notian/220b2d9908eb0e48bec8bc0b08c8a953 to your computer and use it in GitHub Desktop.
<?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