jquery-element-class

JavaScript performance comparison

Revision 2 of this test case created

Info

Determine whether or not prefacing a class-name with an element name achieves any performance boost with jQuery selectors.

Hypothesis: like in CSS, adding an element name to the class name will not provide any performance boost, because selectors are evaluated right-to-left. Also, pseudo-selectors are slow.

Preparation code

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

Preparation code output

Shown

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Selector Plus Class
$("div.visible").hide();
pending…
Class Only
$(".visible").hide();
pending…
Pseudo Class
$(".visible:visible").hide();
pending…
.is(':visible')
var d = $(".visible");

if (d.is(":visible")) {
  d.hide();
}
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