jQuery .data() performance vs .attr() performance (v113)

Revision 113 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<input type="text" id="theInput" data-foo="bar" value="foo"></input>
<script>
  var theInput = $('#theInput');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Attribute get
theInput.attr('data-foo');
ready
Data get
theInput.data('foo');
ready
Direct data get
$.data(theInput, 'foo');
ready
DOM getAttribute get
theInput[0].getAttribute("foo")
ready

Revisions

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