cloneNode vs createElement

JavaScript performance comparison

Revision 10 of this test case created by sandeep

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    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";
};
</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 = 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";
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