Append Array of jQuery Elements

JavaScript performance comparison

Test case created by Peter

Preparation code

<div id="test"></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="test"></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
Append in each
$.each($elts, function(i, $elt) {
    $test.append($elt);
});
pending…
Convert to list of DOM elements and append
var elts = $.map($elts, function($elt) {
    return $elt.get();
});
$test.append(elts);
pending…
Append list of jQuery elements
$test.append($elts);
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