Chain IDs vs single ids

JavaScript performance comparison

Test case created by Yochannah

Preparation code

<form id="newUserForm">
  <div class="control-group">
   <label class="control-label" for="emailAddress">Email Address:</label>
  <div class="controls">
     <input type="text" id="emailAddress" name="emailAddress" value="" placeholder="e.g. bob@example.com" />
  </div>
</div>
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    var $form = $(document.getElementById('newUserForm'));
   
};
</script>

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
Element, directly
var $email = $(document.getElementById('emailAddress'));
 
pending…
Element, via stored variable
var $email = $form.find(document.getElementById('emailAddress'));
 
pending…
using jQuery's # syntax
var $email = $('#emailAddress');
 
pending…

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

Compare results of other browsers

0 comments

Add a comment