String Concat vs Array join

JavaScript performance comparison

Test case created

Info

Comparing speed of string concatenation vs pushing to an array and then joining at the end.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var quantum = 'abcd';
    var emptyArray = [];
    var emptyString = '';
};

Benchmark.prototype.teardown = function() {
    var finalStringFromArray = emptyArray.join(' ');
};
</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
String concat
emptyString += ' '+ quantum;
pending…
Array join
emptyArray.push(quantum);
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