hasObjectMoreThanNProperties

Benchmark created on


Setup

const a = Array(6000);
a.fill(1);
const o = a.reduce((acc, v, i) => {
	acc[`${i}`] = i;
	return acc;
}, {})

Test runner

Ready to run.

Testing in
TestOps/sec
Using loop
function hasObjectMoreThanNProperties(o, n) {
  let count = 0;
  for (const _ in o) {
    count += 1;
    if (count > n) {
      return true;
    }
  }
  return false;
}
console.log(hasObjectMoreThanNProperties(100))
ready
Using Object.keys
console.log(Object.keys(o).length > 100)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.