hasObjectMoreThanNProperties (v2)

Revision 2 of this benchmark created on


Setup

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

function hasObjectMoreThanNProperties(o, n) {
  let count = 0;
  for (const _ in o) {
    count += 1;
    if (count > n) {
      return true;
    }
  }
  return false;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Using loop - low N
hasObjectMoreThanNProperties(100)
ready
Using Object.keys
Object.keys(o).length
ready
Using loop - high N
hasObjectMoreThanNProperties(5000)
ready

Revisions

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