Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
filtering array with push vs reduce
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0
Browser:
Firefox 115
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
filter with push
174374.3 Ops/sec
filter with reduce
1016.5 Ops/sec
Script Preparation code:
var arr = new Array(1000); for (let i = 0; i < 1000; ++i) { arr[i] = i % 2 === 0 ? true : null; }
Tests:
filter with push
const result = []; for (const item of arr) { if (item != null) { result.push(item); } } return result;
filter with reduce
return arr.reduce( (arr, item) => (item != null ? [...arr, item] : arr), [], );