Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
if for loop speed test v2
testing for loop stuff
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/104.0.5112.20 Safari/537.36
Browser:
Chrome 104
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
one for loop and one if statement
40.7 Ops/sec
one for loop and manipulating value of index
41.8 Ops/sec
no if checks just many for loops
41.9 Ops/sec
Tests:
one for loop and one if statement
function allcharsIndex(n = 0, limit = 65520) { if (typeof n !== "number") { // eslint-disable-next-line no-throw-literal throw "parameter 1 is not of type number"; } if (typeof limit !== "number") { // eslint-disable-next-line no-throw-literal throw "parameter 2 is not of type number"; } if (limit > 65520) limit = 65520; function getCh(eye) { let cnt = 0; let char = String.fromCharCode(eye); let cg = char; while (cnt++ < n) { char = `${char}${cg}`; } return char; } let characters = [getCh(32), getCh(33)]; for (let i = 35; i < 65520; i++) { if (characters.length >= limit) return [...characters]; if ( i === 92 || i === 127 || i === 128 || i === 129 || i === 130 || i === 131 || i === 132 || i === 133 || i === 134 || i === 135 || i === 136 || i === 137 || i === 138 || i === 139 || i === 140 || i === 141 || i === 142 || i === 143 || i === 144 || i === 145 || i === 146 || i === 147 || i === 148 || i === 149 || i === 150 || i === 151 || i === 152 || i === 153 || i === 154 || i === 155 || i === 156 || i === 157 || i === 158 || i === 159 || i === 173 || i === 1536 || i === 1537 || i === 1538 || i === 1539 || i === 1540 || i === 1807 || i === 6068 || i === 6069 || i === 8204 || i === 8205 || i === 8206 || i === 8207 || i === 8232 || i === 8233 || i === 8234 || i === 8235 || i === 8236 || i === 8237 || i === 8238 || i === 8239 || i === 8288 || i === 8289 || i === 8290 || i === 8291 || i === 8292 || i === 8293 || i === 8294 || i === 8295 || i === 8296 || i === 8297 || i === 8298 || i === 8299 || i === 8300 || i === 8301 || i === 8302 || i === 8303 || i === 65279 ) continue; characters.push(getCh(i)); } return [...characters]; } allcharsIndex();
one for loop and manipulating value of index
function allcharsIndex(n = 0, limit = 65520) { if (typeof n !== "number") { // eslint-disable-next-line no-throw-literal throw "parameter 1 is not of type number"; } if (typeof limit !== "number") { // eslint-disable-next-line no-throw-literal throw "parameter 2 is not of type number"; } if (limit > 65520) limit = 65520; function getCh(eye) { let cnt = 0; let char = String.fromCharCode(eye); let cg = char; while (cnt++ < n) { char = `${char}${cg}`; } return char; } let characters = [getCh(32), getCh(33)]; for (let i = 35; i < 65520; i++) { if (characters.length >= limit) return [...characters]; if (i === 127) { i = 159; continue; } if (i === 1536) { i = 1540; continue; } if (i === 8204) { i = 8207; continue; } if (i === 8232) { i = 8239; continue; } if (i === 8288) { i = 8303; continue; } if (i === 8288) { i = 8303; continue; } if ( i === 92 || i === 173 || i === 1807 || i === 6068 || i === 6069 || i === 65279 ) continue; characters.push(getCh(i)); } return [...characters]; } allcharsIndex();
no if checks just many for loops
function allcharsIndex(n = 0, limit = 65520) { if (typeof n !== "number") { // eslint-disable-next-line no-throw-literal throw "parameter 1 is not of type number"; } if (typeof limit !== "number") { // eslint-disable-next-line no-throw-literal throw "parameter 2 is not of type number"; } if (limit > 65520) limit = 65520; function getCh(eye) { let cnt = 0; let char = String.fromCharCode(eye); let cg = char; while (cnt++ < n) { char = `${char}${cg}`; } return char; } let characters = [getCh(32), getCh(33)]; for (let i = 35; i < 92; i++) { if (characters.length >= limit) return [...characters]; characters.push(getCh(i)); } for (let i = 93; i < 127; i++) { if (characters.length >= limit) return [...characters]; characters.push(getCh(i)); } for (let i = 160; i < 173; i++) { if (characters.length >= limit) return [...characters]; characters.push(getCh(i)); } for (let i = 174; i < 1536; i++) { if (characters.length >= limit) return [...characters]; characters.push(getCh(i)); } for (let i = 1541; i < 1807; i++) { if (characters.length >= limit) return [...characters]; characters.push(getCh(i)); } for (let i = 1808; i < 6068; i++) { if (characters.length >= limit) return [...characters]; characters.push(getCh(i)); } for (let i = 6070; i < 8204; i++) { if (characters.length >= limit) return [...characters]; characters.push(getCh(i)); } for (let i = 8208; i < 8232; i++) { if (characters.length >= limit) return [...characters]; characters.push(getCh(i)); } for (let i = 8240; i < 8288; i++) { if (characters.length >= limit) return [...characters]; characters.push(getCh(i)); } for (let i = 8304; i < 65279; i++) { if (characters.length >= limit) return [...characters]; characters.push(getCh(i)); } for (let i = 65280; i < 65520; i++) { if (characters.length >= limit) return [...characters]; characters.push(getCh(i)); } return [...characters]; } allcharsIndex();