jquery is awesome

JavaScript performance comparison

Revision 3 of this test case created and last updated

Preparation code

<div id="Stupid_Div">
  Stupid Crap
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
Benchmark.prototype.teardown = function() {
    $('#Stupid_div').html('');
};
</script>

Preparation code output

Stupid Crap

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Jquery
var mainDiv = $('#Stupid_Div');
var elements = [];
elements = [document.createElement('div').id = 'test1', document.createElement('div').id = 'test2', document.createElement('div').id = 'test3', document.createElement('div').id = 'test4']
mainDiv.html(elements);
pending…
Vanilla JS
//Returns a new Buffer object

function Buffer() {
  "use strict";
  //the framgment
  var domFragment = document.getElementById("Stupid_Div");
  domFragment.innerHTML = "";
  //Adds a node to the dom fragment

  function add(node,id) {
    var domInsert = domFragment.appendChild(document.createElement(node));
    domInsert.id = id ;
  }

  //Flushes the buffer to a node

  function flush(targetNode) {

    //if the target node is not given then use the body
    var targetNode = targetNode || document.body;

    //append the domFragment to the target
    targetNode.appendChild(domFragment);

  }

  //return the buffer
  return {
    "add": add,
    "flush": flush
  };
}


//to make a buffer do this
var buffer = Buffer();


//continue to add elements to the buffer
buffer.add("div",'test1');
buffer.add("div",'test2');
buffer.add("div",'test3');
buffer.add("div",'test4');
 
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