Re[2]: [PHP] preg_replace brain teaser

From: Date: Wed, 16 Apr 2003 14:24:09 +0000
Subject: Re[2]: [PHP] preg_replace brain teaser
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-144117@lists.php.net to get a copy of this message
Hi, Wednesday, April 16, 2003, 11:44:11 PM, you wrote: Ssd> OKOK call me stupid ; ) Looks like I need a vacation real bad... Ssd> The second testcase should actually look like this: Ssd> preg_replace($pattern2, 'callback1', $string); Ssd> to give a decent test so the results I posted earlier actually are Ssd> irrelevant since its executing the same code.... Ssd> Here are the results of the new run using the above code for the second Ssd> test case Ssd> All 1000 Results evaluation: Ssd> Total Time 1: 0.00018324580562115 Ssd> Total Time 2: 2.1518136978149E-005 (0.00002151813) Ssd> So Tom Roger you are right !!! Ssd> Using the callback seems to be faster by a magnitude of almost 10. Ssd> So you should favour preg_replace_callback over preg_replace with the 'e' Ssd> modifier. Ssd> Stefan Langer You also have a little bug in the preg_replace which is throwing a warning.. It should be: preg_replace($pattern1, "\$args['\\1']", $string); (It likes the array index in quotes.) That may even the scores a bit The result I got with just 10 loops All 10 Results evaluation: Total Time 1: 0.073623263835907 ms Total Time 2: 0.0426864306132 ms I multiplied the reult by 1000 to get milliseconds Still quite a bit quicker -- regards, Tom

« previous php.general (#144117) next »