Re: IF statement question...

From: Date: Wed, 19 May 2004 14:49:21 +0000
Subject: Re: IF statement question...
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-186535@lists.php.net to get a copy of this message
Curt Zirzow wrote:
* Thus wrote Oliver Hankeln (oha@walter-interactive.de):
100000 Searches in a rather small string took 0.38s with strpos() and 0.55s with preg_match()
Make sure your benchmarks aren't bias: - assignment takes time - concating string takes time
You are right. I updated the script to: [...] $regexp="/".$needle."/"; $t1=getmicrotime(); for($i=0;$i<100000;$i++)
    strpos($haystack,$needle);
$t2=getmicrotime(); for($i=0;$i<100000;$i++)
    preg_match($regexp,$haystack);
$t3=getmicrotime(); [...] Now the time is 0.33s vs. 0.46s. preg_match needs 139.4% of the strpos time Oliver

« previous php.general (#186535) next »