jQuery .data() performance vs .prop() performance (v52)

Revision 52 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
<input type="text" id="theInput" value="foo"></input>
<script>
  var theInput = $('#theInput');
  theInput.prop('someAttr', 'theValue').data('someData', 'theValue').attr('x-custom', 'yep');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
prop() get
theInput.prop('someAttr');
ready
prop() set
theInput.prop('someAttr', 'newValue');
ready
Data get
theInput.data('someData');
ready
Data set
theInput.data('someData', 'newValue');
ready
Data Modified get
theInput.data().someData;
ready
Data Modified set
theInput.data().someData = 'newValue';
ready
Data get direct
var test = $.data(theInput[0],'someData');
ready
Data set direct
$.data(theInput[0], 'someData','test1');
ready
set prop
theInput[0].someAttr = "test1";
ready
get prop
var test = theInput[0].someAttr;
ready
getAttribute
var test = theInput[0].getAttribute('someAttr');
ready
get attr()
theInput.attr('x-custom');
ready
set attr
theInput.attr('x-custom', 'newValue');
ready

Revisions

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