Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Array.includes vs Object.hasOwnProperty vs Reflect.has vs object[id]
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:143.0) Gecko/20100101 Firefox/143.0
Browser:
Firefox 143
Operating system:
Windows
Device Platform:
Desktop
Date tested:
7 months ago
Test name
Executions per second
array.includes
716.7 Ops/sec
Object.prototype.hasOwnProperty
503251.9 Ops/sec
object.hasOwnProperty
627103.8 Ops/sec
Reflect.has
453113.2 Ops/sec
object[field]
528885.3 Ops/sec
Script Preparation code:
var ids = ['']; var entities = { '': { id: '', number: 10000 } }; var id = ''; for (let i = 0; i < 10000; i++) { id = String(i); ids.push(id); entities[id] = { id, number: i } } function getRandomInt(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min) + min); //The maximum is exclusive and the minimum is inclusive } var idsFind = ['']; for (let i = 0; i < 100; i++) { idsFind.push(String(getRandomInt(0, 20000))); }
Tests:
array.includes
var result = []; for (const id of idsFind) { if (ids.includes(id)) { result.push(entities[id]) } } return result
Object.prototype.hasOwnProperty
var result = []; for (const id of idsFind) { if (Object.prototype.hasOwnProperty.call(entities, id)) { result.push(entities[id]) } } return result
object.hasOwnProperty
var result = []; for (const id of idsFind) { if (entities.hasOwnProperty(id)) { result.push(entities[id]) } } return result
Reflect.has
var result = []; for (const id of idsFind) { if (Reflect.has(entities, id)) { result.push(entities[id]) } } return result
object[field]
var result = []; for (const id of idsFind) { if (entities[id] != null) { result.push(entities[id]) } } return result