For/for of/for in/forEach comparison (v23)

Revision 23 of this benchmark created on


Setup

function f(x) {
    return x*x/2;
  }
  
    const map = new Map();
    for (let i = 0; i < 1000; i++) {
        map.set(i, i * 2);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Normal for loop
    for (const [key, value] of map) {
        f(key + value);
    }
ready
Normal for loop, length cached

    map.forEach((value, key) => {
        f(key + value);
    });
ready
entries
    for (const [key, value] of map.entries()) {
        f(key + value);
    }
ready
keys
    for (const key of map.keys()) {
        f(key + map.get(key));
    }
ready

Revisions

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