jQuery vs JavaScript Performance Comparison

JavaScript performance comparison

Revision 47 of this test case created

Info

document.getElementsByClassName

Preparation code

<script src="//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

Test runner

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

Java applet disabled.

Testing in unknown unknown
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. Here’s a list of current revisions for this page:

0 comments

Add a comment