JMU
ECMAScript/JavaScript Profiling
Using Firebug


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu


Getting Started
The Process
  1. Start Firefox
  2. Start Firebug by clicking on images/firebug-logo.gif in the toolbar
  3. Select the Console tab
  4. Select "All"
  5. Start the profiling process by clicking on "Profile"
  6. Load the HTML page containing the code to profile
  7. Use the code
  8. Stop the profiling process by clicking on "Profile" (which will generate the report)
Network Performance
An Example

Profiling a 1-Dimensional Optimization Algorithm Click here for a demonstration.

ecmascriptexamples/optimization/GoldenSection.js
        
/**
 * See if two floating point values are approximately equal
 *
 * @param a {number}   One value
 * @param b {number}   The other value
 * @return             true if a and b are approximately equal
 */
function equals(a, b)
{
   "use strict";   

   if (Math.abs(a-b) < 0.000001){return true;}
   return false;
}


/**
 * Return the midpoint between two floating point values
 *
 * @param a {number}   One value
 * @param b {number}   The other value
 * @return             The midpoint
 */
function midpoint(a, b)
{
   "use strict";   

   return (a+b)/2.0;   
}


/**
 * Minimize a "well-behaved" function of one variable using the Golden
 * Section algorithm. Note: If the solution is not be within the bounds
 * this function will iterate forever.
 *
 * @param  f   The function
 * @param  L_0 The lower bound of the search space
 * @param  U_0 The upper bound of the search space
 * @return The value of x that minimizes f (i.e., the argmin over [L_0, U_0])
 */
function argminGoldenSection(f, L_0, U_0)
{
   "use strict";   
   var L, t_L, t_R, U;

   // Initialize
   L = L_0;
   U = U_0;

   t_L = L + 0.382*(U - L);
   t_R = L + 0.618*(U - L);

   // Iterate
   while (!equals(L,U)){
      if (f(t_L) < f(t_R)){
//       L   = L;
         U   = t_R;
         t_R = t_L;
         t_L = L + 0.382*(U - L);
      }else{
         L   = t_L;
//       U   = U;
         t_L = t_R;
         t_R = L + 0.618*(U - L);
      }
  }

   return midpoint(L,U);
}


        

Profiling an n-Dimensional Optimization Algorithm Click here for a demonstration.