Re: regular expressions: HUGE speed differences

From: Date: Sat, 06 Apr 2002 14:53:32 +0000
Subject: Re: regular expressions: HUGE speed differences
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-91863@lists.php.net to get a copy of this message
PIII 400MHz, 512Mb, SuSe 6.4, 2.2.14 smp, php 3.0.16, Completed in 0.76187908649445 seconds PIII 350MHz, 256Mb, Suse 7.3, 2.4.9, php 4.0.6, Completed in 2.6342689990997 seconds File Size:28537kb, But for "real tests", send the original file you use direct BTW How the hell did you develop this monstrous eregi? For better maintenance, I´d cut it in several pieces, or first make the inputfile smaller using grep " a href" > to test.file , This will reduce fileaccess a lot, and takes microseconds to proceed. Oliver At 06.04.2002 15:01, you wrote:
Im using a regular expression, to get all urls from a file. When using it on the webserver, it processes a 25kb html file about 0.25 seconds (PIII 350, 128mb ram, linux 2.2.13-7mdk, php 3.0.12). When i try the same on my machine (Celeron 300A, 192mb ram.), it does it about 14-17 seconds, which is about 60-70 times slower. Tested it on: redhat 7.2, php 4.1.1 - 16 seconds windows 98, php 4.1.1 - 14 seconds windows 98, php 3.0.12 - 17 seconds. The machine speed differences arent that big, especially considering that other(simpler) regexps run at the almost the same speed (20-30% difference). Where can this enourmous speed difference come from <snip>
Anyone care to test it on there machine? Full code (20 lines) with
timing function would be: <? function getmicrotime(){
    list($usec, $sec) = explode(" ",microtime());
    return ((float)$usec + (float)$sec);
    }
//change to some html file around 25kb in size $lines = @file('test.html'); if (is_array($lines))
    {
    while (list($id,$line) = each($lines))
           $file .= $line;
} $start_time=getmicrotime(); while (eregi("(<frame[^>]*src[[:blank:]]*=|href[[:blank:]]*=|http-equiv=['\"]refresh['\"] *content=['\"][0-9]+;url[[:blank:]]*=|window[.]location[[:blank:]]*=|window[.]open[[:blank:]]*[(])[[:blank:]]*[\'\"]?(([[a-z]{3,5}://(([.a-zA-Z0-9-])+(:[0-9]+)*))*([:%/?=&;\\,._a-zA-Z0-9-]*))(#[.a-zA-Z0-9-]*)?[\'\" ]?",$file,$regexp)) { print $regexp[2]."\n"; $file=str_replace($regexp[0], "", $file); } $end_time = getmicrotime()- $start_time; print "Completed in ".$end_time." seconds"; ?>


« previous php.general (#91863) next »