Data attribute vs.jQuery().data (v19)

Revision 19 of this benchmark created on


Preparation HTML

<script src="https://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);
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Data attribute
k = Math.floor(Math.random() * 1001)
$el.attr('data-key-' + k, 'val-' + Math.floor(Math.random() * 1001));
$el.attr("data-key-" + k);
ready
jQuery.fn.data
k = Math.floor(Math.random() * 1001)
$el.data('key-' + k, 'val-' + Math.floor(Math.random() * 1001));
$el.data("key-" + k);
ready

Revisions

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