Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
i hate l00ps with optimaze for and with function
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/123.0.0.0 Safari/537.36
Browser:
Chrome 123
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
functional
768.8 Ops/sec
imperative
622.3 Ops/sec
functional but better
841.3 Ops/sec
imperative with function
624.6 Ops/sec
Script Preparation code:
var numbers = Array.from({ length: 10_000 }).map(() => Math.random())
Tests:
functional
const result = numbers .map(n => Math.round(n * 10)) .filter(n => n % 2 === 0) .reduce((a, n) => a + n, 0)
imperative
let result = 0 for (let i = 0,len =numbers.length; i <len ; i++) { let n = Math.round(numbers[i] * 10) if (n % 2 !== 0) continue result = result + n }
functional but better
const round = n => Math.round(n * 10) const isEven = n => n % 2 === 0 const result = numbers .reduce((a, n) => { n = round(n) return isEven(n) ? a + n : a; }, 0)
imperative with function
const round = n => Math.round(n * 10) const isEven = n => n % 2 === 0 let result = 0 for (let i = 0,len =numbers.length; i <len ; i++) { let n = round(numbers[i]) if (!isEven(n)) continue result = result + n }