1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00
joplin/packages/utils/time.ts

30 lines
756 B
TypeScript
Raw Normal View History

2023-12-13 21:24:58 +02:00
export const Second = 1000;
export const Minute = 60 * Second;
export const Hour = 60 * Minute;
export const Day = 24 * Hour;
export const Week = 7 * Day;
export const Month = 30 * Day;
export const msleep = (ms: number) => {
2023-03-21 19:29:22 +02:00
return new Promise(resolve => setTimeout(resolve, ms));
};
// Use the utility functions below to easily measure performance of a block or
// line of code.
interface PerfTimer {
name: string;
startTime: number;
}
const perfTimers_: PerfTimer[] = [];
export function timerPush(name: string) {
perfTimers_.push({ name, startTime: Date.now() });
}
export function timerPop() {
const t = perfTimers_.pop() as PerfTimer;
// eslint-disable-next-line no-console
console.info(`Time: ${t.name}: ${Date.now() - t.startTime}`);
}