array find vs object key
Date tested:
2 months ago
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:135.0) Gecko/20100101 Firefox/135.0
Test name
Executions per second
find
1050238528.0 Ops/sec
Object[key]
1577858304.0 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
var obj = (new Array(1000)).fill(null).reduce((prev, newVal) => {prev[Math.random() + ''] = Math.random() + ''; return prev; }, { sausage: 'tst' }); var array = Object.keys(obj);
Tests:
find
array.find((item) => item === 'sausage')
Object[key]
obj['sausage']
Open this result on MeasureThat.net