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." />
<script src=""></script>
Benchmark.prototype.setup = function() {
    var $form = $(document.getElementById('newUserForm'));

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

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

Compare results of other browsers


Comment form temporarily disabled.

Add a comment