note 118460 deleted from regexp.reference.onlyonce by cmb

From: Date: Mon, 21 Nov 2016 16:33:08 +0000
Subject: note 118460 deleted from regexp.reference.onlyonce by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207259@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- I decided to compare a performance of two patterns: (\D+|<\d+>)*[!?] and ((?>\D+)|<\d+>)*[!?] They said that the first pattern will be slower than second one when the subject string does not contain matches. But this is not truth. <?php $subject = ''; for($i = 0; $i < 100000; $i++) $subject .= 'aBa'; $pattern = '/((?>\D+)|<\d+>)*[!?]/'; $time_start = microtime(true); preg_match($pattern, $subject); $time_end = microtime(true); $time = $time_end - $time_start; echo "Time: $time"; ?> The output will be: Time: 37.874154090881 Meanwhile if we change pattern to '/(\D+|<\d+>)*[!?]/' the output will be: Time: 0.013736963272095

« previous php.notes (#207259) next »