Test name | Executions per second |
---|---|
regex | 105483.6 Ops/sec |
manual | 123752.8 Ops/sec |
switch | 138736.7 Ops/sec |
inline | 137117.0 Ops/sec |
var string = `A CBASCDASC cascasc qwcqwcqwc qwcqwfcqwc
asas
as
as
asas`
let i = 0;
let num = 0;
while (i < string.length) {
if (/\s/.test(string[i])) {
++num;
}
i++;
}
let i = 0;
let num = 0;
while (i < string.length) {
if (" \f\n\r\t\v\u00A0\u2028\u2029".includes(string[i])) {
++num;
}
i++;
}
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++;
}
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++;
}