jQuery().attr vs jQuery().data vs jQuery().prop (v81)

Revision 81 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="el"></div>
<script>
  var i = 0,
      el = document.getElementById('el'),
      $el = $(el),
      setData = function (element, key, value) {
          element['_pref_'+key] = value;
      };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery.fn.attr
$el.attr('key-' + Math.floor(Math.random() * 1001), 'val-' + Math.floor(Math.random() * 1001));
ready
jQuery.fn.data
$el.data('key-' + Math.floor(Math.random() * 1001), 'val-' + Math.floor(Math.random() * 1001));
ready
jQuery.fn.prop
$el.prop('key-' + Math.floor(Math.random() * 1001), 'val-' + Math.floor(Math.random() * 1001));
ready
nativo
el['key-' + Math.floor(Math.random() * 1001)] = 'val-' + Math.floor(Math.random() * 1001);
ready
setData
setData(el,'key-' + Math.floor(Math.random() * 1001),'val-' + Math.floor(Math.random() * 1001));
ready

Revisions

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