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

Revision 53 of this benchmark created 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
dataset
vanillaInput.dataset.someAttr = "foo";
ready

Revisions

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