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 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Browser:
Chrome 126
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
RegEx pre-compiled
7.2M/s
For Loop
5.2M/s
RegEx
2.5M/s
View exact numbers
Test name
Executions per second
✓
RegEx pre-compiled
7,173,980 Ops/sec
For Loop
5,217,650 Ops/sec
RegEx
2,497,135 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);