str_replace vs. preg_replace speed

From: Shawn McKenzie (nospam_at_mckenzies.net)
Date: 12/17/03


To: php-general@lists.php.net
Date: Tue, 16 Dec 2003 23:02:53 -0600

I will run some benchmarks (even though they may be flaky), but what would
be the fastest execution?

$search = array(
            "<!-- [$cmd] -->",
            "<!--[$cmd]-->",
            "<!-- {".$cmd."} -->",
            "<!--{".$cmd."}-->",
            "{".$cmd."}",
        );
$replace = STARTPHP." $action ".ENDPHP;
$tmpcontent = str_replace($search, $replace, $tmpcontent);

Or, if I created one expression that handled all of the five $search items
(since they are similar) and used preg_replace()?

Thanks!
-Shawn



Relevant Pages

  • Re: Whi is it so lsow?
    ... python, what we mostly use here,but they insist its too slow. ... This is one of the more silly "benchmarks". ... Would you like checked array indexing? ... from datetime import datetime ...
    (comp.lang.eiffel)
  • Re: adjustable array vs hash-table
    ... of the hash-table are equal to indices in the array 0.1.2.3.4... ... Expanding when new elements are added when container can't hold ... writing a few simple benchmarks shouldn't be too hard. ... 1st European Lisp Symposium ...
    (comp.lang.lisp)
  • Re: PAS loop faster than BASM
    ... > I created a BASM function that searches through an array of integers ... To my surprise, it benchmarks at about 10 times slower ...
    (borland.public.delphi.language.basm)
  • Re: Frequent crashes, what to look for?
    ... something gone a bit flaky in SWX, maybe its time I upped to WinXP sp2... ... > What is your CPU chip? ... > In your case SpecAPC will thrash your system for an extended period. ... > SpecAPC is one of the oldest benchmarks around. ...
    (comp.cad.solidworks)
  • Re: Count occurences of vars in array
    ... method) from such example array ... def tmtowtdi(ary) ... But there was quite a lot of apparently random and ... purposeless disk i/o going on while the benchmarks were running. ...
    (comp.lang.ruby)