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

Revision 18 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
jQuery attr()
$dom.attr('someAttr','test1');
ready
Attribute get with jQuery object
if ($dom.length > 0)
$dom[0].setAttribute('someAttr','test1');
ready

Revisions

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