Skip to content

Instantly share code, notes, and snippets.

@aliaspooryorik
Last active July 20, 2018 13:55
Show Gist options
  • Select an option

  • Save aliaspooryorik/0b2d4b3186e9f89f96449d879ef2176f to your computer and use it in GitHub Desktop.

Select an option

Save aliaspooryorik/0b2d4b3186e9f89f96449d879ef2176f to your computer and use it in GitHub Desktop.
reg exp speed test
<cfscript>
function test(pattern) {
return ReReplace(s, pattern, "-----", 'all');
}
s = "Fred Bloggs says 'My name is Fred
bloGGs my brother is Alfred Bloggs and I blog about people called fred or freddie'. x:Fred bloggss y: Fred bloggsss Yours FRED BLOGGS";
variations = [
"(?im)(?:(\b|^)Fred\s+Bloggss?(\b|$))",
"(?im)(\b|^)Fred\s+Bloggss?(\b|$)",
"(?im)\bFred\s+Bloggss?\b",
"(?im)(:?(\bFred\s+Bloggss?\b))",
];
iterations = 100000;
for (pattern in variations) {
i = 0;
start = getTickCount();
while(i<iterations) {
i++;
redacted = test();
}
writeoutput("'#pattern#' took" & start-getTickCount() & "<br>");
writeoutput(redacted & "<hr>");
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment