Class or Name Attr Lookup

JavaScript performance comparison

Revision 3 of this test case created by Vaughan

Info

Inspired by this question: In jQuery is it a bad idea to use [name=X] for all selectors?

Add multiple selectors to check suggestions from this question: A convention for indicating whether an HTML element is referenced from JS code

Preparation code

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

<div id="wrapper">
  <div class="title" name="title">My Title is Good!</div>
  <div class="bind title" name="title">My Title is Good!</div>
  <div>Nothing to see here</div>
  <div class="content">
    <p>Lorem ipsum dolor sit amet...</p>
    <p>All your base are belong to us!</p>
  </div>
  <div class="footer">Signing off.</div>
</div>

Preparation code output

My Title is Good!
My Title is Good!
Nothing to see here

Lorem ipsum dolor sit amet...

All your base are belong to us!

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Name w/o scope
$("[name=title]")
pending…
Class w/o scope
$(".title")
pending…
Named w/ scope
$("#wrapper").find("[name=title]")
pending…
Class w/ scope
$("#wrapper").find(".title")
pending…
Children
$("#wrapper").children(".title")
pending…
Class w/o scope (2 selectors)
$(".bind.title")
pending…
Class w/ scope (2 selectors)
$("#wrapper").find(".bind.title")
pending…
Class w/ scope (2 selectors, reversed)
$("#wrapper").find(".title.bind")
pending…
Class w/ nested scopes
$("#wrapper").find(".bind").find(".title")
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