Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
RegEx vs For Loop 2
-
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0
Browser:
Firefox 127
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
RegEx pre-compiled
3.8M/s
For Loop
1.5M/s
RegEx
803K/s
View exact numbers
Test name
Executions per second
✓
RegEx pre-compiled
3,835,679 Ops/sec
For Loop
1,514,608 Ops/sec
RegEx
802,737 Ops/sec
HTML Preparation code:
var string = "asdFORBIDDENasd";
Script Preparation code:
var string = "asdFORBIDDENasd";
Tests:
RegEx
let isPasswordValid = false; let forbiddenValues = ['test', 'another', 'value', 'other', 'foo', 'bar', 'one', 'two', 'three', 'forbidden'] let regexString = forbiddenValues.join('|') let regex = new RegExp('.*(' + regexString + ').*', 'i'); isPasswordValid = regex.test(string);
For Loop
let forbiddenValues = ['test', 'another', 'value', 'other', 'foo', 'bar', 'one', 'two', 'three', 'forbidden'] for (let val of forbiddenValues) { if (string.toLowerCase().includes(val)) { return false; } }
RegEx pre-compiled
let isPasswordValid = false; const regex = new RegExp(/.*(test|another|value|other|foo|bar|one|two|three|forbidden).*/i); isPasswordValid = regex.test(string);