Last active
July 20, 2018 13:55
-
-
Save aliaspooryorik/0b2d4b3186e9f89f96449d879ef2176f to your computer and use it in GitHub Desktop.
reg exp speed test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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