$.data vs $.fn.data

Benchmark created by Paul Irish on


Description

$.fn.data fires some events and also requires creating a new jQuery object.. This should give an idea of the speed difference.

Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
$.data
$.data(document.body, 'string1', 'this string');
$.data(document.body, 'string1'); // "this string"

$.data(document.body, 'obj1', {
 awesome: 'obj',
 sweet: true
});
$.data(document.body, 'obj1'); // obj thing
ready
$.fn.data
$(document.body).data('string1', 'this string');
$(document.body).data('string1'); // "this string"

$(document.body).data('obj1', {
 awesome: 'obj',
 sweet: true
});
$(document.body).data('obj1'); // obj thing
ready

Revisions

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

  • Revision 1: published by Paul Irish on