Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Javascript: reduce VS for
Compare the "reduce" method with the "for" iteration method. Use case: There is an array with different numbers, we will compare the performance between the two methods to find the quantity of numbers greater than zero in the array list.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Linux; arm_64; Android 11; Redmi Note 9S) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.6834.2144 YaApp_Android/25.20.1 YaSearchBrowser/25.20.1 BroPP/1.0 SA/3 Mobile Safari/537.36
Browser:
Chrome 132
Operating system:
Android 25.20.1
Device Platform:
Mobile
Date tested:
one year ago
Number 2: using reduce method
22.0M/s
Number 1: use for iterator
10.2M/s
View exact numbers
Test name
Executions per second
✓
Number 2: using reduce method
22,009,280 Ops/sec
Number 1: use for iterator
10,151,324 Ops/sec
Script Preparation code:
var list = [1, 0, -2, -1, 3, 0, 1, 8, -10, 3, 0, -1, -3];
Tests:
Number 1: use for iterator
let countNumberGreaterThanZero = 0; for (let i = 0; i < list.length; i++) { if (list[i] > 0) { countNumberGreaterThanZero++; } }
Number 2: using reduce method
let countsNumbersGreaterThanZero = (acc, cur) => acc + (cur > 0 ? 1 : 0); list.reduce(countsNumbersGreaterThanZero, 0)