jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
const mockData = createMockData(30, 4);
function getId () {
return Math.floor(Math.random() * 100)
}
function createMockData(itemCount, relationCount){
const arr = []
for(let i = 0; i < itemCount; ++i){
const relations = []
for(let j = 0; j < relationCount; j++){
relations.push({nodeId: getId()})
}
arr.push({id: getId(), relations})
}
return arr;
}
function getNodeIds(arr) {
const idCollection = {};
for (const item of arr) {
const itemId = item.id;
const hasItemIdInRelation = item.relations.some(relation => relation.nodeId === itemId);
if (hasItemIdInRelation) {
idCollection[itemId] = true;
}
}
return idCollection;
}
const idCollection = getNodeIds(mockData);
console.log(mockData)
console.log(idCollection)
Ready to run.
Test | Ops/sec | |
---|---|---|
Nested Array.some |
| ready |
Array.map + Array.some |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.