Iterations

JavaScript performance comparison

Test case created by Gaponov

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const map = new Map();
  const arr = [];
  
  for(let i = 0; i<100000; i++) {
    const value = i.toString();
    map.set(i, value);
    arr.push(value);
  }

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Array iteration
const length = arr.length;
for (let i = 0; i < length; ++i) {
  console.log(arr[i]);
}
pending…
Map for-of iteration
for (const item of map) {
  console.log(item);
}
pending…
Map for-each iteration
map.forEach(item => console.log(item));
pending…
Array for-each iteration
arr.forEach(item => console.log(item));
pending…
Map to array (for-each iteration)
[...map.values()].forEach(item => console.log(item));
pending…
Map for-of iteration
const values = map.values();
for(const item of values) {
  console.log(item);
}
pending…
Map to array (for iteration)
const values = [...map.values()];
const length = values.length;
for (let i = 0; i < length; ++i) {
  console.log(values[i]);
}
pending…

Revisions

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

0 Comments