﻿function PerformanceTimer(inOutputDiv, inEnableOutput)
{
  this.StartTimes = new Object();
  this.PerformanceTimes = new Object();
  this.OutputDivName = inOutputDiv;
  this.OutputEnabled = inEnableOutput;
}

PerformanceTimer.prototype.start = function(inName)
{
  this.StartTimes[inName] = new Date();
}

PerformanceTimer.prototype.stop = function(inName)
{
  var startTime = this.StartTimes[inName];
  var now = new Date();
  var thisPerfTime = 0;
  if (startTime != null)
    thisPerfTime = (now.getTime() - startTime.getTime())/1000;
    
  this.PerformanceTimes[inName] = thisPerfTime;
  return thisPerfTime;
}

PerformanceTimer.prototype.getPerformanceTime = function(inName)
{
  return this.PerformanceTimes[inName];
}

PerformanceTimer.prototype.getAllPerformanceTimes = function ()
{
  return this.PerformanceTimes;
}

PerformanceTimer.prototype.displayResults = function ()
{
  if (!this.OutputEnabled)
    return;
  for (var name in this.PerformanceTimes)
    document.getElementById(this.OutputDivName).innerHTML += name + ": " + this.PerformanceTimes[name] + " seconds<br>";
}