note 118460 added to regexp.reference.onlyonce
| From: | Anonymous | Date: | Thu, 10 Dec 2015 11:31:49 +0000 |
| Subject: | note 118460 added to regexp.reference.onlyonce | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204319@lists.php.net to get a copy of this message | ||
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
----
Server IP: 195.54.192.44
Probable Submitter: 78.155.168.129
----
Manual Page -- http://php.net/manual/en/regexp.reference.onlyonce.php
Edit -- https://master.php.net/note/edit/118460
Del: integrated -- https://master.php.net/note/delete/118460/integrated
Del: useless -- https://master.php.net/note/delete/118460/useless
Del: bad code -- https://master.php.net/note/delete/118460/bad+code
Del: spam -- https://master.php.net/note/delete/118460/spam
Del: non-english -- https://master.php.net/note/delete/118460/non-english
Del: in docs -- https://master.php.net/note/delete/118460/in+docs
Del: other reasons-- https://master.php.net/note/delete/118460
Reject -- https://master.php.net/note/reject/118460
Search -- https://master.php.net/manage/user-notes.php