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

Revision 104 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<input type="text" id="theInput" value="foo"></input>
<script>
  var theInput = document.getElementById("theInput");
  var $theInput = $('#theInput');
  theInput.attr('someAttr', 'theValue').data('someData', 'theValue');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Attribute get
$theInput.attr('someAttr');
ready
Attribute set
$theInput.attr('someAttr', 'newValue');
ready
Data get
theInput.dataset.someData;
ready
Direct data get
$.data($theInput, 'someData');
ready
Direct data set
$.data($theInput, 'someData', 'newValue');
ready

Revisions

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