/*extern Pmx */

/**
 * Pelmorex Timer class
 *
 * @fileoverview
 * This is the source file for the Timer class. This class is used for
 * benchmarking.
 *
 * @author Jim Ing (jing@pelmorex.com)
 */

/**
 * Timer class for benchmarking.
 *
 * @class
 * @constructor
 *
 * @param {string} fname
 *
 * @example
 * var timer = new Pmx.Timer( 'Method Name' );
 * timer.start();
 * // block of source code to benchmark
 * timer.stop();
 * alert( timer.elapsedTime );
 */
Pmx.Timer = function( fname )
{
    this.functionName = fname;
    this.startTime    = 0;
    this.stopTime     = 0;
    this.elapsedTime  = 0;
};

/**
 * @description
 * Start the timer.
 */
Pmx.Timer.prototype.start = function()
{
    this.startTime = new Date();
};

/**
 * @description
 * Stop the timer. This will output the function name and elapsed time to
 * Firebug's console if the Pmx.debug and Pmx.console.log options are set to
 * true.
 */
Pmx.Timer.prototype.stop = function()
{
    this.stopTime = new Date();
    this.elapsedTime = ( this.stopTime - this.startTime ) / 1000;

    if( Pmx.debug === true && Pmx.console.log === true )
    {
        console.log( this.functionName + ': ' + this.elapsedTime + ' secs.' );
    }

    // TODO: Need a better way to do this outside of the class.
    if( document.getElementById( Pmx.Map.elemId.stat_time ) && this.functionName == 'drawRoads' )
    {
        document.getElementById( Pmx.Map.elemId.stat_time ).innerHTML = this.elapsedTime + ' secs.';
    }
};
