'use strict';

/*
 * Copyright 2014 Google Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

/**
 * Init a timer
 * @constructor
 */
function Timer() {
    this.start_time = Date.now();
    this.results = [];
}

/**
 * Save start of the an event and display msg on the console
 * @param {string} msg
 */
Timer.prototype.time_start = function(msg) {
  console.time('@@@ ' + msg);
  console.timeStamp('@@@ begin ' + msg);
  var cur_time = Date.now() - this.start_time;
  this.results.push('begin ' + msg + ' at ' + cur_time + '\n');
  console.log('@@@ begin ' + msg + ' at ' + cur_time);
};

/**
 * Save end of the an event and display msg on the console
 * @param {string} msg
 */
Timer.prototype.time_end = function(msg) {
  console.timeEnd('@@@ ' + msg);
  console.timeStamp('@@@ end ' + msg);
  var cur_time = Date.now() - this.start_time;
  this.results.push('end ' + msg + ' at ' + cur_time + '\n');
  console.log('@@@ end ' + msg + ' at ' + cur_time);
};


@@ -737,16 +737,43 @@
 s = %5B%5D;%0A
+    this.timing_info = %7B%7D;%0A
 %7D%0A%0A/**%0A 
@@ -875,21 +875,16 @@
 ototype.
-time_
 start = 
@@ -1132,24 +1132,208 @@
  cur_time);%0A
+  var info = %7B%7D;%0A  if (this.timing_info%5Bmsg%5D) %7B%0A    console.log('**** duplicate: %22' + msg + '%22');%0A  %7D%0A  info%5B'name'%5D = msg;%0A  info%5B'start'%5D = cur_time;%0A  this.timing_info%5Bmsg%5D = info;%0A
 %7D;%0A%0A/**%0A * S
@@ -1434,13 +1434,8 @@
 ype.
-time_
 end 
@@ -1686,12 +1686,1470 @@
 _time);%0A
+  var info = this.timing_info%5Bmsg%5D;%0A  info%5B'end'%5D = cur_time;%0A%7D;%0A%0A/**%0A * Display the timing info on the page.%0A * @param %7BObject%7D table DOM table element.%0A */%0ATimer.prototype.display_timing = function(table) %7B%0A  var arr = %5B%5D;%0A  for (var key in this.timing_info) %7B%0A    arr.push(this.timing_info%5Bkey%5D);%0A  %7D%0A  arr.sort(function(a, b) %7B%0A    return a%5B'start'%5D - b%5B'start'%5D;%0A  %7D);%0A%0A  for (var i = 0; i %3C arr.length; i++) %7B%0A    var info = arr%5Bi%5D;%0A    var name = info%5B'name'%5D;%0A    var start = info%5B'start'%5D;%0A    var end = info%5B'end'%5D;%0A    var delta;%0A    if (end) %7B%0A      delta = end - start;%0A    %7D else %7B%0A      end = '?';%0A      delta = '?';%0A    %7D%0A    var row = table.insertRow(table.rows.length);%0A    var cell = 0;%0A    this._appendTimingCell(row, cell++, name, 'left');%0A    this._appendTimingCell(row, cell++, start, 'right');%0A    this._appendTimingCell(row, cell++, end, 'right');%0A    this._appendTimingCell(row, cell++, delta, 'right');%0A  %7D%0A%7D;%0A%0A/**%0A * Add a timing cell.%0A * @param %7B!Object%7D row DOM row element.%0A * @param %7BNumber%7D pos The position in the row element.%0A * @param %7BString%7CNumber%7D value The value to display.%0A * @param %7BString%7D align The alignment value.%0A */%0ATimer.prototype._appendTimingCell = function(row, pos, value, align) %7B%0A  var cell = row.insertCell(pos);%0A  var mytype = typeof value;%0A  if (typeof value === 'number')%0A    cell.innerHTML = '' + Math.round(value);%0A  else%0A    cell.innerHTML = value;%0A  if (align)%0A    cell.style.textAlign = align;%0A
 %7D;%0A
-%0A

Add code to display the timing info on the page.