HTML Preparation code:
AخA
 
1
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"><script>
2
<script>jQuery.noConflict();</script>
3
<script src="https://cdnjs.cloudflare.com/ajax/libs/cash/7.0.3/cash.min.js"></script>
4
<div id="foo" class="foo2"></div>
Tests:
  • getElementById

     
    var el = document.getElementById("foo");
    var className = el.className;
  • getElementsByClassName

     
    var el = document.getElementsByClassName("foo2");
    var className = el.className;
  • getElementsByTagName

     
    var el = document.getElementsByTagName("div")[0];
    var className = el.className;
  • querySelector (#id)

     
    var el = document.querySelector('#foo');
    var className = el.className;
  • querySelector (.id)

     
    var el = document.querySelector('.foo2');
    var className = el.className;
  • querySelectorAll (#id)

     
    var el = document.querySelectorAll('#foo');
    var className = el.className;
  • querySelectorAll (.id)

     
    var el = document.querySelectorAll('.foo2');
    var className = el.className;
  • Cash (#id)

     
    var el = $("#foo");
    var className = el.className;
  • Cash (.id)

     
    var el = $(".foo2");
    var className = el.className;
  • Cash (tag#id)

     
    var el = $("div#foo");
    var className = el.className;
  • Cash (tag.id)

     
    var el = $("div.foo2");
    var className = el.className;
  • Cash + getElementById

     
    var el = $(document.getElementById("foo"));
    var className = el.className;
  • Cash + getElementsByClassName

     
    var el = $(document.getElementsByClassName("foo2"));
    var className = el.className;
  • jQuery (#id)

     
    var el = jQuery("#foo");
    var className = el.className;
  • jQuery (.id)

     
    var el = jQuery(".foo2");
    var className = el.className;
  • jQuery (tag#id)

     
    var el = jQuery("div#foo");
    var className = el.className;
  • jQuery (tag.id)

     
    var el = jQuery("div.foo2");
    var className = el.className;
  • jQuery + getElementById

     
    var el = jQuery(document.getElementById("foo"));
    var className = el.className;
  • jQuery + getElementsByClassName

     
    var el = jQuery(document.getElementsByClassName("foo2"));
    var className = el.className;
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    getElementById
    getElementsByClassName
    getElementsByTagName
    querySelector (#id)
    querySelector (.id)
    querySelectorAll (#id)
    querySelectorAll (.id)
    Cash (#id)
    Cash (.id)
    Cash (tag#id)
    Cash (tag.id)
    Cash + getElementById
    Cash + getElementsByClassName
    jQuery (#id)
    jQuery (.id)
    jQuery (tag#id)
    jQuery (tag.id)
    jQuery + getElementById
    jQuery + getElementsByClassName

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Chrome 121 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
getElementById 11050676.0 Ops/sec
jQuery (tag.id) 1585707.1 Ops/sec
jQuery (tag#id) 1411618.5 Ops/sec
jQuery (.id) 2631563.0 Ops/sec
jQuery (#id) 4627566.0 Ops/sec
Cash + getElementsByClassName 2929756.2 Ops/sec
Cash + getElementById 4495168.0 Ops/sec
Cash (tag.id) 2309697.5 Ops/sec
jQuery + getElementById 5006050.5 Ops/sec
Cash (tag#id) 1932334.5 Ops/sec
Cash (#id) 5040011.5 Ops/sec
querySelectorAll (.id) 3045331.2 Ops/sec
querySelectorAll (#id) 2679043.5 Ops/sec
querySelector (.id) 6098783.5 Ops/sec
querySelector (#id) 4262768.5 Ops/sec
getElementsByTagName 8326466.5 Ops/sec
getElementsByClassName 6958161.5 Ops/sec
Cash (.id) 3034542.2 Ops/sec
jQuery + getElementsByClassName 1746162.6 Ops/sec