functions in jQuery.each

JavaScript performance comparison

Revision 2 of this test case created by Justin Force

Info

Is there a performance difference when declaring your function before or inline used with jQuery.each?

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></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
pre-defined function
var body = $('body'), doSomething = function () {
  body.append('<div class=' + this);
};
$.each([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], doSomething);
pending…
inline function
var body = $('body');
$.each([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], function () {
  body.append('<div class=' + this);
});
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