Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
RegEx vs For Loop 4
-
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/120.0.0.0 Safari/537.36
Browser:
Chrome 120
Operating system:
Linux
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
For Loop
6136471.5 Ops/sec
RegEx
3430198.2 Ops/sec
HTML Preparation code:
var string = "passw)odas4gsdfsdf";
Script Preparation code:
var string = "passw)odas4gsdfsdf";
Tests:
For Loop
const FORBIDDEN_CHARACTERS = [`<`, `>`, `&`, `$`]; for (const character of FORBIDDEN_CHARACTERS) { const position = string.indexOf(character); if (position !== -1) { return INVALID; } }
RegEx
const FORBIDDEN_CHARACTERS = [`<`, `>`, `&`, `$`]; const forbiddenRegex = new RegExp(`[${FORBIDDEN_CHARACTERS.join('')}]`); const match = forbiddenRegex.exec(string); if (match) { return INVALID; }