Files
api/app/core/utils/debugging/debug-timer.ts
2021-09-02 17:30:33 +09:30

27 lines
570 B
TypeScript

/*!
* Copyright 2019-2020 Lime Technology Inc. All rights reserved.
* Written by: Alexis Tyler
*/
import { performance } from 'node:perf_hooks';
import { log } from '../../log';
const timers = new Map();
/**
* Debug timer
*/
export const debugTimer = (timerName: string): void => {
// Start new timer
if (!timers.has(timerName)) {
timers.set(timerName, performance.now());
return;
}
const timeLengthInMs = performance.now() - timers.get(timerName);
log.timer(`${timerName}: ${timeLengthInMs}`);
// Remove existing timer
timers.delete(timerName);
};