Array.join vs concatenation (with non-empty join value)

JavaScript performance comparison

Test case created by Josh

Preparation code

<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.compat.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    var arr = _.range(1000),
        result;
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
String.concat
var str = "";
for (var i = 0; i < 1000; ++i)
  str = str.concat(arr[i],';');
result = str;
pending…
String +=
var str = "";
for (var i = 0; i < 1000; ++i)
  str += arr[i] + ';';
result = str;
pending…
Array.join
var str = [];
for (var i = 0; i < 1000; ++i)
  str.push(arr[i]);
result = str.join(";");
pending…

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

Compare results of other browsers

0 comments

Add a comment