$.ready vs $(fn)

JavaScript performance comparison

Test case created by Aaron Powell

Info

Is the implied function better or not?

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
  var doc = $(document);
</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
$(document).ready
$(document).ready(function() {
  var i = 1;
  i++;
});
pending…
$(fn)
$(function() {
  var i = 1;
  i++;
});
pending…
Cached $(document)
doc.ready(function() {
  var i = 1;
  i++;
});
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:

4 comments

gbakernet commented :

Why is $.ready in this test. It doesn't take a function as an argument.

gbakernet commented :

Add another whereby Preparation is the same as internal $(fn) reference js doc = jQuery(document);

Iteration js doc.ready(fn)

Aaron Powell (revision owner) commented :

@gbakernet - yeah having $.ready was a mistake, I misread what it did.

sam commented :

yeah $.ready was my mistake ... caching $(document) makes sense, not sure it is worth the extra key length though

Add a comment