jQuery .data() performance vs .attr() performance vs elem.getAttribute() (v16)

Revision 16 of this benchmark created on


Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
Attribute get
dom.setAttribute('someAttr','test1');
ready
Data get
$dom.data('someData','test1');
ready
Direct data get
$.data($dom, 'someData','test1');
ready
getAttribute()
 
ready

Revisions

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