map-vs-loop

JavaScript performance comparison

Test case created by Knagis

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var a = [1, 5, 2, 10, 12, -12, 0, 4];

};
</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
for2
var x = new Array(a.length);

for (var i = 0; i < a.length; i++) {
    x[i] = a[i] + 1;
}
pending…
for
var x = [];

// for..of transpiled by TS
/*
for (let val of a) {
    x.push(val + 1);
}
*/
for (var _i = 0, a_1 = a; _i < a_1.length; _i++) {
    var val = a_1[_i];

    x.push(val + 1);
}
pending…
map
x = a.map(val => val + 1);
pending…

Revisions

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

0 Comments