Array map and join vs loop and string concatenation

JavaScript performance comparison

Revision 60 of this test case created

Preparation code

<script>
    var data = Array.apply (null, new Array (1e4))
        .map (function (a, i){ return i });
    function fn (arg){
        return arg.toString (2);
    }
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Array map and join
var output = data.map (fn).join ('; ');
pending…
Loop and string concatenation
var output = fn (data [0]);

for (var i = 1; i < data.length; i ++)
    output += '; ' + fn (data [i]);
pending…
var output = myarray.join('');
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. Here’s a list of current revisions for this page:

0 comments

Add a comment