Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
reduce vs forEach vs for loop on a string
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/138.0.0.0 Safari/537.36
Browser:
Chrome 138
Operating system:
Windows
Device Platform:
Desktop
Date tested:
9 months ago
Test name
Executions per second
Array.prototype.reduce.call()
410621.8 Ops/sec
Array.prototype.forEach.call()
0.0 Ops/sec
Conventional for loop
350663.2 Ops/sec
Script Preparation code:
var strToConvert = "yr89vi083hf*/:<>?\\|*/:<>?\\|*/:<>?\\|*/:<>?\\|*/:<>?\\|*/:<>?\\|984hijhfgvjhngkjqherkjfherh"; String.prototype.validFNCharReduce=function(o,e){ const HW='"*/:<>?\\|',FW='"*/:<>?\\|',F=String.fromCharCode; return Array.prototype.reduce.call(this, o && Object.hasOwn(o,"char") && (e=o.char, !0) ? (r,c) => r + (HW.includes(c)?e:c) : o?.reverse ? (r,c) => r + (FW.includes(c)?F(c.charCodeAt(0)-65248):c) : (r,c) => r + (HW.includes(c)?F(c.charCodeAt(0)+65248):c) , "") }; String.prototype.validFNCharForEach=function(o,e){ const HW='"*/:<>?\\|',FW='"*/:<>?\\|',F=String.fromCharCode; let r="";i Array.prototype.forEach.call(this, o && Object.hasOwn(o,"char") && (e=o.char, !0) ? c => r += (HW.includes(c)?e:c) : o?.reverse ? c => r += (FW.includes(c)?F(c.charCodeAt(0)-65248):c) : c => r += (HW.includes(c)?F(c.charCodeAt(0)+65248):c) ) return r }; String.prototype.validFNCharForLoop=function(o){ const h='"*/:<>?\\|',f='"*/:<>?\\|',F=String.fromCharCode; let c,e,r="",i=0,T=this,l=T.length; if(o && Object.hasOwn(o,"char")) for(e=o.char;i<l;i++) r+=h.includes(c=T[i])?e:c; else if(o?.reverse) for(;i<l;i++) r+=f.includes(c=T[i])?F(T.charCodeAt(i)-65248):c; else for(;i<l;i++) r+=h.includes(c=T[i])?F(T.charCodeAt(i)+65248):c; return r };
Tests:
Array.prototype.reduce.call()
strToConvert.validFNCharReduce()
Array.prototype.forEach.call()
strToConvert.validFNCharForEach()
Conventional for loop
strToConvert.validFNCharForLoop()