cloneNode vs createElement

JavaScript performance comparison

Revision 4 of this test case created by Rhys Brett-Bowen

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></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
JS Clone
var a = document.createElement('div');
var b = a.cloneNode(false);
var c = a.cloneNode(false);
var d = a.cloneNode(false);
var e = a.cloneNode(false);
var f = a.cloneNode(false);
pending…
JS Create
var a = document.createElement('div');
var b = document.createElement('div');
var c = document.createElement('div');
var d = document.createElement('div');
var e = document.createElement('div');
var f = document.createElement('div');
pending…
jQuery Clone
var a = $('<div />');
var b = a.clone();
var c = a.clone();
var d = a.clone();
var e = a.clone();
var f = a.clone();
pending…
jQuery Create
var a = $('<div />');
var b = $('<div />');
var c = $('<div />');
var d = $('<div />');
var e = $('<div />');
var f = $('<div />');
pending…
cloneNode deep
var a = document.createElement('div');
var b = a.cloneNode(true);
var c = a.cloneNode(true);
var d = a.cloneNode(true);
var e = a.cloneNode(true);
var f = a.cloneNode(true);
pending…
jQuery one pass
var tmp = $('<div /><div /><div /><div /><div /><div />');
var a = tmp[0];
var b = tmp[1];
var c = tmp[2];
var d = tmp[3];
var e = tmp[4];
var f = tmp[5];
pending…
div innerHTML
var tmp = document.createElement('div');
tmp.innerHTML = '<div></div><div></div><div></div><div></div><div></div><div></div>';
var a = tmp.childNodes[0];
var b = tmp.childNodes[1];
var c = tmp.childNodes[2];
var d = tmp.childNodes[3];
var e = tmp.childNodes[4];
var f = tmp.childNodes[5];
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