UNPKG

if-logger

Version:

`if-logger` can set whether to log or not dynamically

34 lines 1.25 kB
"use strict"; exports.__esModule = true; var StopWatch = /** @class */ (function () { function StopWatch(printLog) { this.times = []; this.printLog = printLog; } StopWatch.prototype.start = function (title) { this.header = title ? "[" + title + "] " : ''; this.times = [Date.now()]; this.printLog(this.header + 'start'); }; StopWatch.prototype.check = function (label) { if (this.times.length === 0) { this.printLog('[error] start() has not yet been called'); return; } this.times.push(Date.now()); var diff = this.times[this.times.length - 1] - this.times[this.times.length - 2]; var total = this.times[this.times.length - 1] - this.times[0]; this.printLog(this.header + label + (" (" + diff + "ms / " + total + "ms)")); }; StopWatch.prototype.reset = function () { var total = this.times[this.times.length - 1] - this.times[0]; this.printLog(this.header + ("end (total: " + total + "ms)")); this.times = []; }; StopWatch.prototype.end = function () { this.reset(); }; return StopWatch; }()); exports["default"] = StopWatch; //# sourceMappingURL=StopWatch.js.map