jquery vs createElement vs cloning

JavaScript performance comparison

Revision 125 of this test case created

Info

Table cell (containing a class) jQuery creation with jQuery, document.createElement, jQuery.clone and element.cloneNode

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    var $toBeCloned = jQuery('<td class="Some"></td>'),
        toBeCloned = document.createElement('td');
    toBeCloned.setAttribute('class', 'Some');
};
</script>

Preparation code output

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(html)
var test = jQuery('<td class="Some"/>');
pending…
document.createElement
var el = document.createElement('td'), test;
el.setAttribute('class', 'Some');
test = jQuery(el);
pending…
jQuery.clone
var test = $toBeCloned.clone();
 
pending…
element.cloneNode
var test = jQuery(toBeCloned.cloneNode(false));
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

Comment form temporarily disabled.

Add a comment