Append string vs join array

JavaScript performance comparison

Revision 28 of this test case created by

Preparation code

<script src="https://code.jquery.com/jquery-2.0.3.min.js"></script>
<div id="fox"></div>
      
<script>
Benchmark.prototype.setup = function() {
  var i = 0, str = '', arr = [],
  w1 = 'brown', w2 = 'jumped', w3 = 'lazy';
  var element = $('#fox');

};

Benchmark.prototype.teardown = function() {
  $('#fox').empty();

};
</script>

Preparation code output

<div id="fox"></div>

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
String append #1
'Quick ' + w1 + 
' fox ' + w2 + 
' over the ' + w3 + 
' dog. ';
pending…
String append #2
element.append('Quick ' + w1 + ' fox ' + w2 + ' over the ' + w3 + ' dog. ');
pending…
Array join #1
['Quick ', w1, 
' fox ', w2, 
' over the ', w3, 
' dog. '].join('');
pending…
Array join #2
element.text('Quick ' + w1 + ' fox ' + w2 + ' over the ' + w3 + ' dog. ').text;
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