Skip to content

Instantly share code, notes, and snippets.

@amalmurali47
Created January 8, 2014 15:42
Show Gist options
  • Save amalmurali47/8318735 to your computer and use it in GitHub Desktop.
Save amalmurali47/8318735 to your computer and use it in GitHub Desktop.
<?php
/*
Took 10.474477052689 seconds
Took 12.499534845352 seconds
*/
set_time_limit( 0 );
$searchText = 'Page and Brin originally nicknamed THEIR new search engine "BackRub", because the system checked backlinks to estimate the importance of a site.';
$start = microtime_float();
for( $i = 0 ; $i < 1000000 ; $i++ )
{
preg_match_all("/[A-Z]{1}[a-zA-z]*/", $searchText, $matches );
}
$total = microtime_float() - $start;
echo "Took $total seconds<br/>";
$str = $searchText;
$start = microtime_float();
for( $i = 0 ; $i < 1000000 ; $i++ )
{
foreach (str_word_count($str, 1) as $key => $value) {
if (ctype_upper($value)) $arr[] = $value;
}
}
$total = microtime_float() - $start;
echo "Took $total seconds<br/>";
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment