jQuery elements creation vs. native elements creation

JavaScript performance comparison

Test case created and last updated

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</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
jQuery elements creation
var $tr_node = $('<tr>');
for (var i = 0; i < 100; i++) {
  $('<td>', {
    'class': 'dataList'
  }).appendTo($tr_node);
}
pending…
Native elements creation
var tr_node = document.createElement('tr');
for (var i = 0; i < 100; i++) {
  var td_node = document.createElement('td');
  td_node.class = 'dataList';
  tr_node.appendChild(td_node);
}
pending…
jQuery and native hybrid
var $tr_node = $(document.createElement('tr'));
for (var i = 0; i < 100; i++) {
  var $td_node = $(document.createElement('td'), {
    'class': 'dataList'
  });
  $tr_node.append($td_node);
}
pending…
Document fragment
var tr_node = document.createElement('tr');
var td_nodes = document.createDocumentFragment();
for (var i = 0; i < 100; i++) {
  var td_node = document.createElement('td');
  td_node.class = 'dataList';
  td_nodes.appendChild(td_node);
}
tr_node.appendChild(td_nodes);
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. Here’s a list of current revisions for this page:

0 comments

Add a comment