Re: Re: execution time: preg vs ereg vs explode & implode

From: Date: Wed, 12 Jun 2002 18:48:36 +0000
Subject: Re: Re: execution time: preg vs ereg vs explode & implode
References: 1 2 3  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-6964@lists.php.net to get a copy of this message
For the archives: <?php $a="http://foo.bar"; $t = time(); for ($i=0; $i<1000000;$i++) eregi('^http$', $a); echo "eregi: " . (time() - $t) . "s\n"; $t = time(); for ($i=0; $i<1000000;$i++) preg_match('|^http$|i', $a); echo "preg: " . (time() - $t) . "s\n"; ?> Output: eregi: 12s preg: 5s El mié, 12-06-2002 a las 20:37, Jon Abernathy escribió: > > D'oh! What would have been my first post to this list and I had forgotten to > CC it... figures. > > Happy to oblige. > > > - Jon Abernathy, jon@alpineinternet.com | jon@chuggnutt.com > > > Tim Gallagher > > I *ALWAYS* forget that stupid str_replace! > > Ha! > > > > good idea, thanks. > > > > -timmyg > > > > At 09:33 AM 6/12/2002 -0700, you wrote: > > >Tim Gallagher writes: > > > > Can anyone tell me if using explode is slower, or faster or nearly the > > >same > > > > as using preg. > > > > > > > > I understand that preg is faster than ereg, is this true? How much > > >faster? > > > > > > > > here's my code, i want to take a file that has {{{ or }}} and > explode on > > > > both. > > > > should I use preg_split instead? Would it be faster? > > > > > > > > > > > > $ar = explode("{{{", $fileContents); > > > > $ar = implode(":::", $ar); > > > > $ar = explode("}}}", $ar); > > > > $ar = implode(":::", $ar); > > > > > >Wouldn't it be quicker to use str_replace to eliminate these four steps? > I'm > > >thinking: > > > > > >$ar = str_replace( array('{{{', '}}}'), ':::', > > >$fileContents ); > > > > > > > $ar = explode(":::", $ar); > > > > > >Otherwise, a while back I remember a thread on one of the discussion > lists > > >referring to some informal benchmarks which showed explode() and split() > > >(the ereg version) to be about equal in speed, and preg_split() having no > > >significant speed advantage over either. Of course, take this with a > grain > > >of salt. I myself almost always use split(). > > > > > > > > >- Jon Abernathy, jon@alpineinternet.com | jon@chuggnutt.com > > > > > > > -- > PEAR Development Mailing List (http://pear.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.pear.dev (#6964) next »