Re: Regex in PHP

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

 



On Wed, 2008-06-04 at 13:12 -0400, Robert Cummings wrote:
> On Wed, 2008-06-04 at 10:56 -0600, Nathan Nobbe wrote:
> > On Wed, Jun 4, 2008 at 10:26 AM, Robert Cummings <robert@xxxxxxxxxxxxx>
> > wrote:
> > 
> > > Nope, case insensitive is slower since you must make two tests for
> > > characters having a lower and upper case version. With case sensitive
> > > comparisons you only need to make a single comparison.
> > 
> > 
> > a quick test shows stripos beating strpos.
> > 
> > <?php
> > 
> > $str = 'asSAFAASFDADSfasfjhalskfjhlaseAERQWERQWER;.dafasjhflasfjd';
> > $search = 'fdasASDFAafdas';
> > 
> > $start = microtime();
> > strpos($str, $search);
> > $end = microtime();
> > $r1 = $end - $start;
> > 
> > $start = microtime();
> > 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;
> > }
> > ?>
> 
> 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.

Here's my results on my Athlon 2400, 10 million loops on each type using
your script settings for $str and $search and making 3 runs each time:

strpos()
===========================================
real    0m7.133s
user    0m6.480s
sys     0m0.020s

real    0m6.134s
user    0m6.068s
sys     0m0.016s

real    0m6.527s
user    0m6.476s
sys     0m0.012s

stripos()
===========================================
real    0m13.720s
user    0m13.517s
sys     0m0.072s

real    0m13.158s
user    0m13.009s
sys     0m0.016s

real    0m13.151s
user    0m13.013s
sys     0m0.012s

Now, that's how you test efficiency. Doing a single run is very, very
subject to whatever else your processor might be doing and as such is
usually garbage for any kind of analysis.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[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