Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
non empty object
(version: 0)
Comparing performance of:
Object.getOwnPropertyNames vs Object.keys vs for .. in vs for .. of Object.getOwnPropertyNames vs JSON vs Reflect
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
function createObj(len) { const obj = {}; for (let i=0;i<25;i++) { obj[(Math.random*Math.random()).toString()] = (Math.random()*Math.random()) / Math.random() } return obj; }
Tests:
Object.getOwnPropertyNames
const obj = createObj(); const notEmpty = o => Object.getOwnPropertyNames(o).length > 0; console.log(notEmpty(obj))
Object.keys
const obj = createObj(); const notEmpty = o => Object.keys(o).length > 0; console.log(notEmpty(obj))
for .. in
const obj = createObj(); const notEmpty = o => { for (const k in o) { if (o.hasOwnProperty(k)) return true; } return false; } console.log(notEmpty(obj))
for .. of Object.getOwnPropertyNames
const obj = createObj(); const notEmpty = o => { for (const k of Object.getOwnPropertyNames(o)) { if (o.hasOwnProperty(k)) return true; } return false; } console.log(notEmpty(obj))
JSON
const obj = createObj(); const notEmpty = o => { return JSON.stringify(o)!=='{}'; } console.log(notEmpty(obj))
Reflect
const obj = createObj(); const notEmpty = o => { return Reflect.ownKeys(o).length > 0 } console.log(notEmpty(obj))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
Object.getOwnPropertyNames
Object.keys
for .. in
for .. of Object.getOwnPropertyNames
JSON
Reflect
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Comments
Confirm delete:
Do you really want to delete benchmark?