Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
empty test
(version: 0)
Comparing performance of:
for loop vs every
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
for loop
const isEmpty = value => { if (!value && value !== 0 && value !== false) { return true; } else if (Array.isArray(value)) { for (let i = 0; i < value.length; i++) { if (!isEmpty(value[i])) { return false; } } return true; } else if (typeof value === 'object') { for (let prop in value) { if (value.hasOwnProperty(prop) && !isEmpty(value[prop])) { return false; } } return true; } return false; }; isEmpty({arr:[0, null, null, null], ai:'', io:{arr:[null, null, null, null, 1]}});
every
const isEmpty2 = value => { if (!value && value !== 0 && value !== false) { return true; } if (Array.isArray(value)) { return value.every(isEmpty2); } if (typeof value === 'object') { return Object.values(value).every(isEmpty2); } return false; }; isEmpty2({arr:[0, null, null, null], ai:'', io:{arr:[null, null, null, null, 1]}});
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
for loop
every
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!
Related benchmarks:
Check if empty object is empty
Empty vs check
Is string empty
string empty literal vs length
empty string 3
Comments
Confirm delete:
Do you really want to delete benchmark?