Testing Map methods

JavaScript performance comparison

Test case created by jrsinclair

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const str = `Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui.`;
  const arr = (new Array(1000)).fill({str});
  const f = x => x.str.split().slice(1).reverse();

};
</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
Built-in map
function map(f, a) {
    return a.map(f);
}

map(f, arr);
pending…
for-of
function map(f, a) {
    const out = [];
    for (el of a) {
        out.push(f(el));
    }
    return out;
}


map(f, arr);
pending…
for-loop: forwards
function map(f, a) {
    const out = [];
    const len = a.length;
    for (i = 0; i < len; i++) {
        out.push(f(a[i]));
    }
    return out;
}


map(f, arr);
pending…
for-loop: backwards
function map(f, a) {
    const out = [];
    const len = a.length;
    for (i = len - 1; i >= 0; i--) {
        out[i] = f(a[i]);
    }
    return out;
}


map(f, arr);
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