Attribute vs Class selection (v4)

Revision 4 of this benchmark created on


Description

Tests speed of selection for data attribute selection versus class-based selection.

Preparation HTML

<ul>
<li id="1" data-cargroup="A" class="js-CarGroup-A">A</li>
<li id="2" data-cargroup="B" class="js-CarGroup-B">B</li>
<li id="3" data-cargroup="C" class="js-CarGroup-C">C</li>
<li id="4" data-cargroup="C" class="js-CarGroup-C">C</li>
<li id="5" data-cargroup="D" class="js-CarGroup-D">D</li>
</ul>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Setup

for (var i = 0; i < 4000; i++) {
      $("ul").prepend('<li data-cargroup="' + i + '" class="js-CarGroup-' + i +    '">' + i + '</li>'); 
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Data-attribute selection
$('li[data-cargroup = "C"]');
ready
Class-based selection
$('li.js-CarGroup-C');
ready

Revisions

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