jQuery.data vs jQuery().data

JavaScript performance comparison

Revision 33 of this test case created by Dmitry

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="rs-index-1" class="data-index-5" data-index="5"></div>
<div id="rs-index-2" class="data-index-10" data-index="10"></div>
<div id="rs-index-3" class="data-index-8" data-index="4"></div>

<script>
  var i = 0,
      el = jQuery('#el');
el.attr('data-index', 10);
el.addClass('data-index-10');
</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
jQuery.data
jQuery(document).find('.data-index-10');
pending…
jQuery.fn.data
jQuery(document).find('div[data-index="10"]');
pending…
123
jQuery(document).find('[data-index="10"]');
pending…
456

jQuery(document).find('#rs-index-3');
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