Weedpacket;10897475 wrote:I wonder how "#--+#" will perform? Probably compiles to the same NFA as NogDog's; if it does it would be the same.
EDIT - Unless I am missing something here, isn't PCRE strictly NFA based regardless?
Well, for anyone interested, here is the test code (nothing spectacular, but does its job I suppose):
time.php
$comparison = array('#-{2,}#', '#--+#');
$str = 'this---is-my--string';
$loop = 1000;
echo '• target string: (" ' . $str . ' ")<br />' . '• num. of iterations: ' . $loop . '<br /><br />';
foreach($comparison as $val){
$time_start = microtime(true);
for($i = 0; $i < $loop; $i++){
$matches = preg_replace($val ,'-', $str);
}
$time_end = microtime(true);
$elapsed_time = round($time_end-$time_start, 4);
echo "Pattern: " . htmlentities($val) . "<br />time: $elapsed_time seconds<br />";
echo 'Output:<br />' . '<pre>' . print_r($matches, true) . '<br /><hr noshade="false" size="1" />';
}
I used to just pitch in preg pattern suggestions without actually testing beforehand how efficient [or in-efficient] they are (and still do at times).. but figured I would just pull up time.php everytime I need to test some patterns to see the end results.
And as for Weed's suggestion, the results seem to sway back and forth.. so close enough either way.