Data Selector performance without values (v2)

Revision 2 of this benchmark created by Mario Estrada on


Description

We're comparing the performance of a jQuery selector that selects a data attribute AND its value, and another without the value

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="test">
<div class="yj-chat-menu-user">
  <button class="yj-chat-menu-item unstyle-button-as-div js-open-chat" data-js-open-chat data-js-open-chat-val="1">
    <img src="http://placehold.it/24x24" alt="" width="24" height="24">
    <div class="yj-presence yj-chat-user-presence yj-online" data-yj-user-id="1337">
      <span class="yj-acc-hidden">online</span>
    </div>
    <div class="yj-chat-user-name">John Stamos</div>
    <div class="yj-chat-user-job">Jessee And The Rippers</div>
  </button>
  <button class="yj-chat-menu-item unstyle-button-as-div js-open-chat" data-js-open-chat data-js-open-chat-val="1">
    <img src="http://placehold.it/24x24" alt="" width="24" height="24">
    <div class="yj-presence yj-chat-user-presence yj-online" data-yj-user-id="1337">
      <span class="yj-acc-hidden">online</span>
    </div>
    <div class="yj-chat-user-name">John Stamos</div>
    <div class="yj-chat-user-job">Jessee And The Rippers</div>
  </button>
  <button class="yj-chat-menu-item unstyle-button-as-div js-open-chat" data-js-open-chat data-js-open-chat-val="1">
    <img src="http://placehold.it/24x24" alt="" width="24" height="24">
    <div class="yj-presence yj-chat-user-presence yj-online" data-yj-user-id="1337">
      <span class="yj-acc-hidden">online</span>
    </div>
    <div class="yj-chat-user-name">John Stamos</div>
    <div class="yj-chat-user-job">Jessee And The Rippers</div>
  </button>
</div>
</div>

Setup

var div = $('#test')

Test runner

Ready to run.

Testing in
TestOps/sec
dataSelectorWithVal
div.find('[data-js-open-chat-val="1"]');
ready
dataSelectorWithOutVal
div.find('[data-js-open-chat]');
ready
classSelector
div.find(".js-open-chat");
ready

Revisions

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

  • Revision 1: published by paceaux on
  • Revision 2: published by Mario Estrada on
  • Revision 3: published by AdrienBrault on
  • Revision 4: published by Rob on
  • Revision 5: published by Rob on