.appendChild Vs jQuery.append()

JavaScript performance comparison

Revision 14 of this test case created by Camwyn

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<div id="native"></div>
<div id="jquery"></div>
      
<script>
Benchmark.prototype.setup = function() {
  var native = document.getElementById("native");
  var jquery = $("#jquery");
  
  var obj = document.createElement("div");
  obj.className = 'myObject';
  
  var jQobj = $(obj);
  
  var jqObjString = "<div class='myObject'></div>";

};

Benchmark.prototype.teardown = function() {
  native.innerHTML = "";
  jquery.html("");

};
</script>

Preparation code output

<div id="native"></div> <div id="jquery"></div>

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
Native .insertBefore()
native.insertBefore(obj,native.firstChild);
pending…
jQuery .prepend()
jquery.prepend(jQobj);
pending…
jQuery .prepend() - HTMLplainString
jquery.prepend(jqObjString);
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