1.7303379774094 seconds with strtr()
1.557923078537 seconds with preg_replace()
1.494078040123 seconds with str_replace()
1.4984160661697 seconds with ereg_replace()
/* source -------8<-------*/
<?php
$files = array("html1.html", "html2.html");

$strtr_rep = array( "<pre>" => "PRE",
     "<li>"=>"LI",
     "<tr" => "TABLE ROW START",
     "<b>" => "BOLD",
     "<td" => "TABLE CELL START"
     );
     
/* ----- END CONFIG ------ */
// read in filedata
for ($i = 0; $i < count($files); $i++) {
 $raw[] = implode("", file($files[$i]));
}
// build preg_replace reg/replace pattern arrays
while(list($reg, $rep) = each($strtr_rep)) {
 $preg_reg[]  = "/".$reg."/";
 $preg_repl[] = $rep;
}
//START TEST
$timer = new Timer();

for ($i=0; $i < 1000; $i++) {
 $data = ($i % 2 == 0) ? $raw[0] : $raw[1];
 if ($test == 1) {
  $test = "strtr";
  $data = strtr($data, $strtr_rep);
 } elseif ($test == 2) {
  $test = "preg_replace";
  $data = preg_replace($preg_reg, $preg_repl, $data);
 } elseif ($test == 3) {
  $test = "str_replace";
  while(list($k, $v) = each($strtr_rep)) {
   $data = str_replace($k, $v, $data);
  }
 } elseif ($test == 4) {
  $test = "ereg_replace";
  while(list($k, $v) = each($strtr_rep)) {
   $data = ereg_replace($k, $v, $data);
  }
 }
}
print $timer->getElapsed() . " seconds with $test";
?>
/*  -------8<--------- END SOURCE -----8<------8<----- */
--
Best Regards

Niklas Fondberg  -  [EMAIL PROTECTED]
System Developer  -  I3 Micro Technology


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to