Tuesday, February 24th, 2009

JavaScript Function Call Profiling with FireUnit

Category: jQuery, Performance

John Resig has posted on JavaScript Function Call Profiling and new methods he has added to FireUnit:


Run this method after you’ve run console.profile(); and console.profileEnd(); to get a full dump of the profiling information. For example, given the following profile run:

You’ll get the following JavaScript object returned from fireunit.getProfile():


  1. {
  2.   "time": 8.443,
  3.   "calls": 611,
  4.   "data":[
  5.   {
  6.     "name":"makeArray()",
  7.     "calls":1,
  8.     "percent":23.58,
  9.     "ownTime":1.991,
  10.     "time":1.991,
  11.     "avgTime":1.991,
  12.     "minTime":1.991,
  13.     "maxTime":1.991,
  14.     "fileName":"jquery.js (line 2059)"
  15.   },
  16.   // etc.
  17. ]}

fireunit.profile( fn );

The second method added to FireUnit provides an easy way to execute and profile a single function. Roughly, this method starts the profiler, executes the function, stops the profiler, and then returns the results from getProfile(). Additionally, it watches for any exceptions that might be thrown and makes sure that the profiler is cleanly turned off anyway (a frequent frustration of mine).

You would use it like this:


  1. fireunit.profile(function(){
  2.   document.getElementsByClassName("foo");
  3. });

John then setup a test page and found out some interesting bottlenecks in jQuery, including the current implementation of remove. He has already submitted a patch that cleans it up.

This is great stuff. We used Firebug’s profiling for Bespin but found it a little hard to extrapolate on the data, and we ended up using Shark on the Mac to get more detail on the application as a whole (not just JavaScript).

Posted by Dion Almaer at 12:23 am
Comment here

3.2 rating from 33 votes

Comments Here »

Comments feed TrackBack URI

Leave a comment

You must be logged in to post a comment.