Id id vs id class

JavaScript performance comparison

Revision 2 of this test case created by Joshua T Kalis

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="container">
  <div id="test">
  </div>
  <div id="test2" class="class">
  </div>
</div>

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
ID-ID
var el = $('#container #test')
pending…
ID-Class
var el = $('#container .class')
pending…
ID
var el = $('#test')
pending…
Class
var el = $('.class')
pending…
ID-ID contextual
var el = $('#test', '#container')
pending…
ID-Class contextual
var el = $('.class', '#container')
pending…
ID-ID w/ find()
var el = $('#container').find('#test')
pending…
ID-Class w/ find()
var el = $('#container').find('.class')
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