Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Regex whitespace vs manual checking
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.0.0.0
Browser:
Chrome 137
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
regex
745940.6 Ops/sec
manual
796486.4 Ops/sec
switch
3772638.2 Ops/sec
inline
3361785.5 Ops/sec
Script Preparation code:
var string = `A CBASCDASC cascasc qwcqwcqwc qwcqwfcqwc asas as as asas`
Tests:
regex
let i = 0; let num = 0; while (i < string.length) { if (/\s/.test(string[i])) { ++num; } i++; }
manual
let i = 0; let num = 0; while (i < string.length) { if (" \f\n\r\t\v\u00A0\u2028\u2029".includes(string[i])) { ++num; } i++; }
switch
let i = 0; let num = 0; function test(ch) { switch (ch) { case " ": case "\f": case "\n": case "\r": case "\t": case "\v": case "\u00A0": case "\u2028": case "\u2029": return true; } return false; } while (i < string.length) { const text = string[i]; if (test(text)) { ++num; } i++; }
inline
let i = 0; let num = 0; while (i < string.length) { const ch = string[i]; switch (ch) { case " ": case "\f": case "\n": case "\r": case "\t": case "\v": case "\u00A0": case "\u2028": case "\u2029": ++num; } i++; }