Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Naive some vs using pop shortening vs len trim vs for
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/125.0.0.0 Safari/537.36 Edg/125.0.0.0
Browser:
Chrome 125
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
naive compare
11.9 Ops/sec
compare with pop
8.5 Ops/sec
len trimming
8.5 Ops/sec
for
1.0 Ops/sec
Script Preparation code:
var watched = []; var ignored = []; for(let i = 0; i < 10000; i++){watched.push({programId:Math.random()});} for(let i = 0; i < 10000; i++){ignored.push({programId:Math.random()});}
Tests:
naive compare
watched.filter(obj => { return !ignored.some(item => item.programId === obj.programId); });
compare with pop
watched.filter(wObj => !ignored.some((iObj, ndx) => { if (iObj.programId === wObj.programId) { ignored[ndx] = ignored.pop(); return true; } return false; }) );
len trimming
let ml = ignored.length -1; watched.filter(wObj => !ignored.some((iObj, ndx) => { if (iObj.programId === wObj.programId) { ignored[ndx] = ignored[ml]; ignored.length--; ml--; return true; } return false; }) );
for
let ml = ignored.length -1; watched.filter(wObj => { for (let i = 0; i < ml; i++) { if (wObj.programId === watched[i].programId) { watched[i] = watched[ml]; ml--; return false; } } return true; });