Update app.js

This commit is contained in:
Namhyeon Go 2021-04-29 17:05:53 +09:00
parent 4fb8beb948
commit a04978b130

21
app.js
View File

@ -45,6 +45,7 @@ var exit = function(status) {
var console = {
_timers: {},
_counters: {},
_messages: [],
_join: function(args, sep) {
args = args || [];
@ -88,18 +89,36 @@ var console = {
this._echo(arguments, "debug");
},
time: function(label) {
this._timers[label] = new Date();
label = label || "default";
if (!(label in this._timers)) {
this._timers[label] = new Date();
}
},
timeLog: function(label, end) {
label = label || "default";
if (label in this._timers) {
console.debug(label + ": " + ((new Date()).getTime() - this._timers[label].getTime()) + "ms" + (end ? " - timer ended" : ""));
}
},
timeEnd: function(label) {
label = label || "default";
if (label in this._timers) {
this.timeLog();
delete this._timers[label];
}
},
count: function(label) {
label = label || "default";
if (!(label in this._counters)) {
this._counters[label] = 1;
}
},
countReset: function(label) {
label = label || "default";
if (label in this._counters) {
this.timeLog();
delete this._counters[label];
}
}
};