Object properties iteration

Benchmark created on


Setup

const obj = Object.fromEntries(
  Array.from(
    { length: 9000 },
    () => [String(Math.random()), Math.random()]
  )
);

Test runner

Ready to run.

Testing in
TestOps/sec
for of Object.keys
for (const key of Object.keys(obj)) {};
ready
for counter + Object.keys
const keys = Object.keys(obj);
for (let i = 0, n = keys.length; i < n; i++) { const key = keys[i] };
ready
for in
for (const key in obj) {};
ready
for in + hasOwn
for (const key in obj) {
    if (Object.hasOwn(key)) {
    	continue;
    }
}
ready

Revisions

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