cloneNode vs createElement Performance

JavaScript performance comparison

Revision 53 of this test case created by bskaplou

Preparation code

<script>
  var img = document.createElement("img");
  
  var div = document.createElement("div");
  
  var input = document.createElement("input");
  var sink = null;
  function e(e){return document.createElement(e);}
  function t(e){return document.createTextNode(e);}
</script>
    

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
clone image
sink = img.cloneNode(false);
sink = img.cloneNode(false);
sink = img.cloneNode(false);
sink = img.cloneNode(false);
pending…
create image
sink = document.createElement("img");
sink = document.createElement("img");
sink = document.createElement("img");
sink = document.createElement("img");
pending…
clone div
sink = div.cloneNode(false);
sink = div.cloneNode(false);
sink = div.cloneNode(false);
sink = div.cloneNode(false);
pending…
create div
sink = document.createElement("div");
sink = document.createElement("div");
sink = document.createElement("div");
sink = document.createElement("div");
pending…
clone input
sink = input.cloneNode(false);
sink = input.cloneNode(false);
sink = input.cloneNode(false);
sink = input.cloneNode(false);
pending…
create input
sink = document.createElement("input");
sink = document.createElement("input");
sink = document.createElement("input");
sink = document.createElement("input");
pending…
div createElement shortcut
sink = e("div");
sink = e("div");
sink = e("div");
sink = e("div");
pending…
text createTextNode direct
sink = document.createTextNode("input");
sink = document.createTextNode("input");
sink = document.createTextNode("input");
sink = document.createTextNode("input");
pending…
text createTextNode shortcut
sink = t("input");
sink = t("input");
sink = t("input");
sink = t("input");
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.

0 Comments