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

Revision 29 of this benchmark created by Aris Petridis on


Description

Upgrading to jquery 1.7.1 and also comparing to vanilla js setAttribute() and getAttribute()

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<input type="text" id="theInput" value="foo"></input>
<script>
  var theInput = $('#theInput');
  var vanillaInput = document.getElementById("theInput");
</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.data('someData');
ready
Data set
theInput.data('someData', 'newValue');
ready
Direct data get
$.data(theInput, 'someData');
ready
Direct data set
$.data(theInput, 'someData', 'newValue');
ready
Vanilla attribute set
vanillaInput.setAttribute('someAttr','someValue');
ready
Vanilla attribute get
vanillaInput.getAttribute('someAttr');
ready

Revisions

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