intersect v2d
Date tested:
3 months ago
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0
Test name
Executions per second
some
0.4 Ops/sec
some; pop and swap
178.7 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
Array.prototype.shuffle = function() { let m = this.length, i; while (m) { i = (Math.random() * m--) >>> 0; [this[m], this[i]] = [this[i], this[m]] } return this; }; var watched = []; for(let i = 0; i < 100000; i++){watched.push({programId:Math.random()});} var ignored = [...watched]; ignored.shuffle(); ignored = ignored.slice(50000, 59000);
Tests:
some
let i = 0; watched.filter(wObj => { return !ignored.some((iObj, ndx) => { i++; return iObj.programId === wObj.programId; }); }); console.log(i);
some; pop and swap
let i = 0; watched.filter(wObj => !ignored.some((iObj, ndx) => { if (iObj.programId === wObj.programId) { i++; ignored[ndx].programId = ignored.pop().programId; return true; } return false; }) ); console.log(i);
Open this result on MeasureThat.net