Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
i hate l00ps
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/122.0.0.0 Safari/537.36
Browser:
Chrome 122
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
functional but better
441/s
functional
408/s
imperative
251/s
View exact numbers
Test name
Executions per second
✓
functional but better
441 Ops/sec
functional
408 Ops/sec
imperative
251 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; i < numbers.length; 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)