In the English module and a few other places, users are advised never to use the $& $` and $' variables or their English equivalents $MATCH $PREMATCH $POSTMATCH due to the fact that they will slow down all regex use.
What is a good test case (benchmark) that shows the performance problems?
Here’s a simple starting point, looking for a single character in strings of varying lengths. The match variables make copies of the source string so I expected the penalty to be proportional to the amount of copying required. Reality seems to be the opposite. (This is why we benchmark, children.) The cost of matching against a longer string outweighs the overhead of making a copy. In retrospect, that makes sense, as the copy is just a
memcpywhile the regex engine has to scan character-by-character.Results: