jQuery data() compared between 1.4.2 and 1.4.3

Benchmark created by Dylan F.M. on


Description

Comparing performance of $.data and $().data in jQuery 1.4.2 and 1.4.3.

It appears:

  • $(el).data() is still much slower than $.data()

  • fetching data with both $.data() and $(el).data() in 1.4.3 can be slower than in 1.4.2

  • fetching HTML5 data attributes in 1.4.3 with $(el).data() can be slower than fetching non-HTML5 data attributes

  • setting data with $(el).data() is faster in 1.4.3 than in 1.4.2

  • setting data with $.data() is slower in 1.4.3 than in 1.4.2

Preparation HTML

<div data-pop="fizz"></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
var jQuery142 = $.noConflict();
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script>
var jQuery143 = $.noConflict();
</script>
<script>
  var el142 = jQuery142('div'),
      el143 = jQuery143('div');
  
  el142.data('bang', 'boom');
  el143.data('bang', 'boom');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
1.4.2 set $(el).data()
el142.data('foo', 'bar');
ready
1.4.3 set $(el).data()
el143.data('foo', 'bar');
ready
1.4.2 set $.data()
jQuery142.data(el142, 'foo', 'bar');
ready
1.4.3 set $.data()
jQuery143.data(el143, 'foo', 'bar');
ready
Fetch data with 1.4.2 and $(el).data()
el142.data('bang');
ready
Fetch data with 1.4.3 and $(el).data()
el143.data('bang');
ready
Fetch data with 1.4.2 and $.data()
jQuery142.data(el142, 'bang');
ready
Fetch data with 1.4.3 and $.data()
jQuery143.data(el143, 'bang');
ready
Removed
//
ready
Fetch data attr with 1.4.3 and $(el).data()
el143.data('pop');
ready
Removed
//
ready
Fetch data attr with jQuery 1.4.3 and $.data()
jQuery143.data(el143, 'pop');
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.