cloneNode vs createElement

JavaScript performance comparison

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

Preparation code

<script src=""></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);
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');
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();
jQuery Create
var a = $('<div />');
var b = $('<div />');
var c = $('<div />');
var d = $('<div />');
var e = $('<div />');
var f = $('<div />');
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);
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];
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];

Compare results of other browsers


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:


Comment form temporarily disabled.

Add a comment