For some reason, simply adding the PCRE_UTF8 modifier to the regex input for preg_match()
roughly decuples (x10) the execution time even if no multibyte characters are used. I can't figure out why this is the case and how to best reduce the time. The script used to test is:
$s = microtime(true);
for ($i = 0; $i < 1000; $i++) {
preg_match('/ /u', str_repeat(' ', 50000), $match);
}
$e = microtime(true);
echo "u Modifier:\t".(($e-$s)/$i)."\n";
$s = microtime(true);
for ($i = 0; $i < 1000; $i++) {
preg_match('/ /', str_repeat(' ', 50000), $match);
}
$e = microtime(true);
echo "No Modifier:\t".(($e-$s)/$i)."\n";
The results were:
u Modifier: 2.5037050247192E-5
No Modifier: 2.4969577789307E-6
I tried to see if this was a known bug online, but supposedly, it is not a problem with PHP.
What is this caused by and what would be the best method to execute the match1 quicker?
1"the match" refers to any match. The example used is simply a minimal example and could obviously be matched in much better ways.