for vs array functions

JavaScript performance comparison

Test case created by bendem

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  window.a = [];
  for (let i = 0; i < 1000 * 1000; ++i) {
    a.push(i);
  }

};
</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 functions
const sum1 = a
  .map(a => a * 3)
  .filter(a => a % 2 === 0)
  .reduce((a, b) => a + b, 0);
console.log(sum1);
pending…
for loop
let sum2 = 0;
for (let val of a) {
    val = val * 3;
    if (val % 2 === 0) {
        sum2 += val;
    }
}
console.log(sum2);
pending…

Compare results of other browsers

Revisions

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

0 Comments