Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
testing flatMap, filter and for..of loop
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:120.0) Gecko/20100101 Firefox/120.0
Browser:
Firefox 120
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Test reduce
11220439.0 Ops/sec
test flatMap and filter
7408630.5 Ops/sec
tetsing with for..of loop
21990656.0 Ops/sec
testing flatMap and filter 2
7525118.5 Ops/sec
Script Preparation code:
var customArray1 = [ { advertiser_id: "1", name: "Ricardo", geolocation: "EC", visits_per_month: "6", daily_goal: "6", url: "http://ricardos.com", deleted: "1", }, { advertiser_id: "1", name: "Leonel", geolocation: "CO", visits_per_month: "5", daily_goal: "5", url: "http://leonels.com", deleted: "0", }, ]; var customArray2 = [ { advertiser_id: 1, geolocation: "EC", visits_per_month: 6, daily_goal: 6, url: "http://ricardo.com", id: 1, }, { advertiser_id: 1, geolocation: "CO", visits_per_month: 5, daily_goal: 5, url: "http://leonel.com", id: 2, }, ];
Tests:
Test reduce
customArray1.reduce((acc, item1) => { customArray2.forEach((item2) => { if ( String(item1['advertiser_id']) == String(item2['advertiser_id']) && item1['geolocation'] == item2['geolocation'] && item1['deleted'] !== '1' && (item1['visits_per_month'] !== String(item2['visits_per_month']) || item1['daily_goal'] !== String(item2['daily_goal']) || item1['url'] !== item2['url']) ) { acc.push(item1); } }); return acc; }, []);
test flatMap and filter
customArray2.flatMap((item1) => customArray1.filter( (item2) => String(item1['advertiser_id']) === item2['advertiser_id'] && item1['geolocation'] == item2['geolocation'] && (item1['visits_per_month'] !== String(item2['visits_per_month']) || item1['daily_goal'] !== String(item2['daily_goal']) || item1['url'] !== item2['url']) ) );
tetsing with for..of loop
let result = []; for (let item1 of customArray1) { if (item1.deleted !== '1') { for (let item2 of customArray2) { if ( String(item1['advertiser_id']) == String(item2['advertiser_id']) && item1['geolocation'] == item2['geolocation'] && (item1['visits_per_month'] !== String(item2['visits_per_month']) || item1['daily_goal'] !== String(item2['daily_goal']) || item1['url'] !== item2['url']) ) { result.push(item1); } } } }
testing flatMap and filter 2
customArray1.flatMap((item1) => customArray2.filter( (item2) => String(item1['advertiser_id']) == String(item2['advertiser_id']) && item1['geolocation'] == item2['geolocation'] && item1['deleted'] !== '1' && (item1['visits_per_month'] !== String(item2['visits_per_month']) || item1['daily_goal'] !== String(item2['daily_goal']) || item1['url'] !== item2['url']) ) );