epd
Version:
Enhanced peer dependency resolution for npm, yarn, and pnpm
40 lines • 1.26 kB
JavaScript
export class PerformanceMonitor {
timers = new Map();
metrics = new Map();
start(label) {
this.timers.set(label, Date.now());
}
end(label) {
const start = this.timers.get(label);
if (!start)
return 0;
const duration = Date.now() - start;
this.timers.delete(label);
if (!this.metrics.has(label)) {
this.metrics.set(label, []);
}
this.metrics.get(label).push(duration);
return duration;
}
getReport() {
const report = {};
for (const [label, times] of this.metrics) {
const total = times.reduce((sum, time) => sum + time, 0);
report[label] = {
avg: total / times.length,
total,
count: times.length
};
}
return report;
}
logReport() {
const report = this.getReport();
console.log('\n⚡ Performance Report:');
for (const [label, stats] of Object.entries(report)) {
console.log(` ${label}: ${stats.avg.toFixed(0)}ms avg (${stats.total}ms total, ${stats.count} calls)`);
}
}
}
export const monitor = new PerformanceMonitor();
//# sourceMappingURL=performance.js.map