Curt Zirzow wrote:
Make sure your benchmarks aren't bias:
  - assignment takes time
  - concating string takes time


strpos($haystack,$needle);

  v.s.

preg_match($regex,$haystack);

Just for shits and giggles (and because it's a slow work day), the below script output this...


strpos() : 0.18918436765671
preg_match() : 0.26665662288666

ini_set ( "max_execution_time", "72000" );
function getmicrotime() {
list ( $usec, $sec ) = explode( " ", microtime() );
return ( (float)$usec + (float)$sec );
}
$haystack= "Bob is good.";
$needle = "is";
$regex = "/is/";
$strpos_temp = 0;
$preg_match_temp = 0;
for ( $j = 0; $j < 10000; $j++ ) {
$t1 = getmicrotime();
for ( $i = 0; $i < 100000; $i++ ) {
$pos = strpos ( $haystack, $needle );
}
$t2 = getmicrotime();
for ( $i = 0; $i < 100000; $i++ ) {
preg_match ( $regex, $haystack );
}
$t3 = getmicrotime();
$strpos_temp += $t2 - $t1;
$preg_match_temp += $t3 - $t2;
}
$strpos = $strpos_temp / $j;
$preg_match = $preg_match_temp / $j;
echo ( "strpos() : " . $strpos . "<br />\npreg_match() : " . $preg_match . "<br />\n" );


--
John C. Nichel
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to