String concat + single append vs multiple append

JavaScript performance comparison

Revision 2 of this test case created by

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<style type="text/css">
  .container { height: 50px; width:100%; overflow:hidden}
</style>

<div class="container"></div>
<script>
  var cnt = $('.container');
  var str =  '<div class="sample">test</div>' + 
             '<div class="sample2">test</div>' + 
              '<div class="sample3">test</div>' + 
             '<div class="sample4">test</div>' + 
             '<div class="sample5">test</div>';
  
</script>
    

Preparation code output

<style type="text/css"> .container { height: 50px; width:100%; overflow:hidden} </style> <div class="container"></div> <script> var cnt = $('.container'); var str = '<div class="sample">test</div>' + '<div class="sample2">test</div>' + '<div class="sample3">test</div>' + '<div class="sample4">test</div>' + '<div class="sample5">test</div>'; </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
String concat + single append
$('.container').append(str);
pending…
Multiple append
$('.container').append('<div class="sample">test</div>');
$('.container').append('<div class="sample1">test</div>');
$('.container').append('<div class="sample2">test</div>');
$('.container').append('<div class="sample3">test</div>');
$('.container').append('<div class="sample4">test</div>');
pending…
String concat + single append on cached element
cnt.append(str);
pending…
String concat + multiple append on cached element
cnt.append('<div class="sample">test</div>');
cnt.append('<div class="sample1">test</div>');
cnt.append('<div class="sample2">test</div>');
cnt.append('<div class="sample3">test</div>');
cnt.append('<div class="sample4">test</div>');
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