Append Array of jQuery Elements inside a container

JavaScript performance comparison

Revision 5 of this test case created by thdk

Preparation code

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

      
<script>
Benchmark.prototype.setup = function() {
  var $elts = [];
  for (var i=0; i<100; i++) {
      $elts.push($('<span>', {text: i}));
  }
  var $test = $('#test');

};

Benchmark.prototype.teardown = function() {
  $elts = null;
  $('#test').empty();

};
</script>

Preparation code output

<div id="container"> <div id="test"></div> </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
detach before appending jQuery Elements
$test.detach();
$test.append($elts);
$("body").prepend($test);
pending…

Revisions

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

0 Comments