Test name | Executions per second |
---|---|
indexOf | 2268.4 Ops/sec |
find | 375116.2 Ops/sec |
var objects = [];
for (var i = 0; i < 10000; i++) {
var idx = Math.floor(Math.random() * 1000);
objects.push({
index: idx
});
}
var idx = Math.floor(Math.random() * 1000);
var objectIndices = [];
for (var i = 0; i < 10000; i++) {
objectIndices.push(objects[i].index);
}
var objectIdx = objectIndices.indexOf(idx);
var tempResult = objects[objectIdx];
var tempResult = objects.find(v => v.index === idx);