cloneNode vs createElement

JavaScript performance comparison

Revision 9 of this test case created by sandeep

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 tmp = document.createElement('div');
tmp.style.backgroundColor = "#234567";
tmp.style.position = "absolute";
tmp.style.zIndex = 3;
tmp.style.borderWidth = "1px";
tmp.style.borderColor = "red";

var a = tmp.cloneNode();
var b = tmp.cloneNode();
var c = tmp.cloneNode();
var d = tmp.cloneNode();
var e = tmp.cloneNode();
var f = tmp.cloneNode();
pending…
JS Create
var a = document.createElement('div');

a.style.backgroundColor = "#234567";
a.style.position = "absolute";
a.style.zIndex = 3;
a.style.borderWidth = "1px";
a.style.borderColor = "red";

var b = document.createElement('div');

b.style.backgroundColor = "#234567";
b.style.position = "absolute";
b.style.zIndex = 3;
b.style.borderWidth = "1px";
b.style.borderColor = "red";

var c = document.createElement('div');

c.style.backgroundColor = "#234567";
c.style.position = "absolute";
c.style.zIndex = 3;
c.style.borderWidth = "1px";
c.style.borderColor = "red";

var d = document.createElement('div');

d.style.backgroundColor = "#234567";
d.style.position = "absolute";
d.style.zIndex = 3;
d.style.borderWidth = "1px";
d.style.borderColor = "red";

var e = document.createElement('div');

e.style.backgroundColor = "#234567";
e.style.position = "absolute";
e.style.zIndex = 3;
e.style.borderWidth = "1px";
e.style.borderColor = "red";

var f = document.createElement('div');

f.style.backgroundColor = "#234567";
f.style.position = "absolute";
f.style.zIndex = 3;
f.style.borderWidth = "1px";
f.style.borderColor = "red";
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