jQuery attr vs data

JavaScript performance comparison

Revision 40 of this test case created

Info

This testcase compares the performance from .attr() and .data()

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="test111"><div class="line"></div><div class="line"></div><div class="node"></div><div class="ckbox checked"><input type="checkbox" value="test1.1.1" name="name" text="Test 1.1.1" style="display:none;" checked="checked"></div><div class="file"></div><a checked="true" tvalue="test1.1.1" data-tvalue="test1.1.1" tname="name">Test 1.1.1</a></div>

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
data
var val = $('#test111').find('a').data('tvalue');
pending…
attr
var val = $('#test111').find('a').attr('tvalue');
pending…
attr with data
var val = $('#test111').find('a').attr('data-tvalue');
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