@drift-labs/common
Version:
Common functions for Drift
31 lines • 1.01 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.Stopwatch = void 0;
/**
* A Dev Tool to help with performance analysis.
*
* The stopwatch class should function as a "timer" for a variety of unique keys. Any time a caller calls the "tick" method, with a key, the stopwatch will log the time since the last tick for that key.
*/
class Stopwatch {
constructor() {
this._lastTick = {};
}
/**
* Logs the time since the last tick for the given key.
* @param key The key to log the time for.
*/
tick(key, message) {
const now = Date.now();
const lastTick = this._lastTick[key];
if (lastTick) {
console.log(`⏱️ :: ${message ? ` ${message} ` : ''} \n${key} => ${now - lastTick}ms`);
}
this._lastTick[key] = now;
}
blankTick(key) {
const now = Date.now();
this._lastTick[key] = now;
}
}
exports.Stopwatch = Stopwatch;
//# sourceMappingURL=Stopwatch.js.map
;