jQuery vs JavaScript Performance Comparison

JavaScript performance comparison

Revision 47 of this test case created by

Preparation code

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

      
<script>
Benchmark.prototype.setup = function() {
  function removeAddClass(classToRemove, classToAdd){
    var elems = document.getElementsByClassName(classToRemove);
    var removedElements = [];
    if (!elems) return;
    for (var i=elems.length-1;i>=0;i--) {
      var elem=elems[i];
      var classes=elem.className.split(" ");
      var newClass = classes.splice(classes.indexOf(classToRemove),1).join(" ");
      elem.className=classes + " " + classToAdd;
     }
  }

};
</script>

Preparation code output

<div class="testing"></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
CSS Selecter
var x = document.getElementsByClassName("testing");
var x = removeAddClass('testing', 'funk');
pending…
JS Class
var x = $('.testing').removeClass('testing').addClass('funk');
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