jQuery body vs. document.body selector

JavaScript performance comparison

Revision 31 of this test case created

Info

If you testing selectors test how selectors perform not how innerHTML perform for already selected node. ;)

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="//37.128.149.176/staging/browserkit/browserkit-1.2.0.min.js"></script>
<section id="content">
</section>

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
$('body')
var $body = $('body'),
  str = "How now brown cow",
  i = 100;

while (i--) {
  $body.find('#content').html(str);
}
pending…
$(document.body)
var $body = $(document.body),
  str = "How now brown cow",
  i = 100;

while (i--) {
  $body.find('#content').html(str);
}
pending…
$('body') : not cached
var $body = $('body'),
  str = "How now brown cow",
  i = 100;

while (i--) {
  $body.find('#content').html(str);
}
pending…
$(document.body) : not cached
var $body = $(document.body),
  str = "How now brown cow",
  i = 100;

while (i--) {
  $body.find('#content').html(str);
}
pending…
$('body') : Browserkit
var str = "How now brown cow",
  i = 100;

while (i--) {
  B('#content')[0].innerHTML = str;
}
pending…
document.getElementById
var str = "How now brown cow",
  i = 100;

while (i--) {
  document.getElementById('content').innerHTML = str;
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment