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

JavaScript performance comparison

Revision 46 of this test case created by Joshua Cody

Preparation code

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

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Attribute get
theInput.attr('someAttr');
pending…
Attribute set
theInput.attr('someAttr', 'newValue');
pending…
Data get
theInput.data('someData');
pending…
Data set
theInput.data('someData', 'newValue');
pending…
Direct data get
$.data(theInput, 'someData');
pending…
Direct data set
$.data(theInput, 'someData', 'newValue');
pending…
Date HTML5 passthrough get
theInput.data("someOtherData")
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment