Re: Regex in PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jun 4, 2008 at 2:06 PM, Robert Cummings <robert@xxxxxxxxxxxxx>
wrote:

> On Wed, 2008-06-04 at 11:18 -0600, Nathan Nobbe wrote:
> > On Wed, Jun 4, 2008 at 11:12 AM, Robert Cummings <robert@xxxxxxxxxxxxx>
> > wrote:
> >
> > > Did you just try to use a test that used a single iteration to prove me
> > > wrong? OMFG ponies!!! Loop each one of those 10 million times, use a
> > > separate script for each, and use the system time program to
> > > appropriately measure the time the system takes.
> >
> >
> > <?php
> >
> > $str = 'asSAFAASFDADSfasfjhalskfjhlaseAERQWERQWER;.dafasjhflasfjd';
> > $search = 'fdasASDFAafdas';
> >
> > $start = microtime();
> >
> > for($i = 0; $i < 10000000; $i++)
> >     strpos($str, $search);
> >
> > $end = microtime();
> > $r1 = $end - $start;
> >
> > $start = microtime();
> >
> > for($i = 0; $i < 10000000; $i++)
> >     stripos($str, $search);
> >
> > $end2 = microtime();
> > $r2 = $end2 - $start;
> >
> > echo "strpos: $r1\n";
> > echo "stripos: $r2\n";
> >
> > if($r2 < $r1) {
> >     echo 'stripos is faster' . PHP_EOL;
> > }
> > ------------------------------
> > strpos: 0.730519
> > stripos: -0.098887
> > stripos is faster
>
> Negative time eh!? You're code must be buggy :| The time program works
> like this unde rmost nix systems:
>
>    time php -q foo.php
>
> And then it returns a report of how much time was taken for various
> types of time. I've already sent an email with the appropriate timing of
> both versions. BTW, as primtive as microtime() is for this kind of
> measurement... you might want to read the manual to use it properly:
>
>    http://ca3.php.net/manual/en/function.microtime.php
>
> You probably want:
>
>    microtime( true )
>
> > stripos still dominates ;)  what is this system time program you speak of
> ?
> > and, ill put them into separate programs when i get home this evening,
> and
> > have more time to screw around.
>
> It's a simple thought process to understand that unless someone coding
> the PHP internals buggered their code, that stripos() cannot possibly be
> faster than strpos(). I really don't need benchmarks for something this
> simple to know which SHOULD be faster.
>

i repeated your test using the time program and splitting the script into 2,
one for each strpos and stripos, to find similar results.  imo, there is no
need for 2 comparisons for case-insensitive searches, because both arguments
can be converted to a single case prior to the search.  obviously, there is
a small amount of overhead there the case-sensitive search is unencumbered
by.  i guess i never sat down and thought about how that algorithm would
work (case-sensitive) =/.

thanks for the tips rob.  sorry to bother you richard.

-nathan

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux