UNPKG

advanced-console-log

Version:

Advanced Console Log (ACL), available as the `advanced-console-log` NPM package, is a lightweight logging module for Node.js applications. It supports console and file logging with various levels, colors, and additional features such as memory usage track

36 lines (30 loc) 709 B
class TimerUtility { constructor() { this.timers = {}; } startTimer(label) { this.timers[label] = process.hrtime.bigint(); } stopTimer(label) { if (!this.timers[label]) { return null; } const elapsed = process.hrtime.bigint() - this.timers[label]; delete this.timers[label]; const elapsedTime = `${Number(elapsed / BigInt(1e9))}s ${ Number(elapsed % BigInt(1e9)) / 1e6 }ms`; return elapsedTime; } getTimer(label) { if (!this.timers[label]) { return null; } const elapsed = process.hrtime.bigint() - this.timers[label]; return Number(elapsed / BigInt(1e6)); // Return in milliseconds } clearAllTimers() { this.timers = {}; } } module.exports = TimerUtility;