Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
reduce vs while
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/130.0.0.0 Safari/537.36 Edg/130.0.0.0
Browser:
Chrome 130
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Reduce
144840.2 Ops/sec
while
139828.1 Ops/sec
Tests:
Reduce
const charOccurances = str => str .split("") .reduce((p, c) => ({ ...p, [c]: (p[c] || 0) + 1 }), {}); console.log(charOccurances('abac'));
while
const charOccurances = (str = "") => { const response = {}; while(str.length !== 0) { const char = str.charAt(); const reg = new RegExp(char, "g"); response[char] = str.match(reg).length; str = str.replace(reg, ""); } return response } console.log(charOccurances('abac'));