Attribute vs Class selection

JavaScript performance comparison

Revision 11 of this test case created

Info

Tests speed of selection for attribute selection versus class-based selection.

Preparation code

<div id="popup">
  <input type="text" autofocus="autofocus" aclass class="defaultFocus aclass" />
  <input type="text" autofocus="autofocus" aclass class="defaultFocus aclass" />
  <input type="text" autofocus="autofocus" aclass class="defaultFocus aclass" />
  <input type="text" autofocus="autofocus" aclass class="defaultFocus aclass" />
  <input type="text" autofocus="autofocus" aclass class="defaultFocus aclass" />
  <input type="text" autofocus="autofocus" aclass class="defaultFocus aclass" />
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
  var $container = $("#popup");
</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
attribute selection
$container.find('[autofocus]:not([aclass])');
pending…
Class-based selection
$container.find('.defaultFocus:not(.aclass)');
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