Class vs multiple tag and class selector

Benchmark created by Laurence on


Description

For a class that can appear on multiple tags, is it faster to clarify the selector for each tag or just use the class name

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div class="test">
  <table>
    <tr>
      <td>
        <input type="text" class="ui-editor-input" value="" />
      </td>
      <td>
        <input type="button" class="ui-editor-input" value="" />
      </td>
      <td>
        <input type="checkbox" class="ui-editor-input" value="" />
      </td>
    </tr>
    <tr>
      <td>
        <input type="password" class="ui-editor-input" value="" />
      </td>
      <td>
        <input type="submit" class="ui-editor-input" value="" />
      </td>
      <td>
        <select class="ui-editor-input">
          <option>
            select 1
          </option>
          <option>
            select 2
          </option>
        </select>
      </td>
    </tr>
    <tr>
      <td>
        <input type="text" class="ui-editor-input" value="" />
      </td>
      <td>
      </td>
      <td>
        
      </td>
    </tr>
  </table>
<textarea class="ui-editor-input" rows="5" cols="5">
        </textarea>
<textarea class="ui-editor-input" rows="5" cols="5">
        </textarea>
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
.classname
$('.ui-editor-input').val('test');
ready
multiple tag.classname
$('input.ui-editor-input,textarea.ui-editor-input,select.ui-editor-input').val('test');
ready

Revisions

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

  • Revision 1: published by Laurence on