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

Revision 111 of this benchmark created by Tamas Sz on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<input type="text" id="theInput" value="foo" data-some-data="value"></input>

Test runner

Ready to run.

Testing in
TestOps/sec
Attribute get
$('#theInput').attr('data-some-data');
ready
data get
$('#theInput').data('someData');
ready
data get2
$('#theInput').data('some-data');
ready
data get 3
$('#theInput')[0].dataset['someData']
ready
data get 4
$.data($('#theInput'), 'some-data');
ready
native
document.querySelector('#theInput').dataset['someData'];
ready
native id
document.getElementById('theInput').dataset['someData'];
ready

Revisions

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