Files
api/app/core/utils/debugging/debug-timer.ts
2020-11-11 16:13:30 +10:30

27 lines
565 B
TypeScript

/*!
* Copyright 2019-2020 Lime Technology Inc. All rights reserved.
* Written by: Alexis Tyler
*/
import { performance } from '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);
};