jQuery vs JavaScript Performance Comparison (v47)

Revision 47 of this benchmark created on


Description

document.getElementsByClassName

Preparation HTML

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

Setup

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;
       }
    }

Test runner

Ready to run.

Testing in
TestOps/sec
CSS Selecter
var x = document.getElementsByClassName("testing");
var x = removeAddClass('testing', 'funk');
ready
JS Class
var x = $('.testing').removeClass('testing').addClass('funk');
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.