.data() vs .attr("data-") (v4)

Revision 4 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>(function($){$.fn.d = function(a){return this.attr("data-"+a);};}(jQuery));</script>

<div id="target" data-something="This is some text to be extracted via .data() and .attr()">
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
.data() read
var something = $("#target").data("something");
ready
.attr("data-") read
var something = $("#target").attr("data-something");
ready
.d() read
var something = $("#target").d("something");
ready

Revisions

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