@sentzunhat/zacatl
Version:
A modular, high-performance TypeScript microservice framework for Node.js, featuring layered architecture, dependency injection, and robust validation for building scalable APIs and distributed systems.
21 lines • 761 B
JavaScript
import { performance } from 'perf_hooks';
import { logger } from '../logs/index.js';
export const measureExecutionTime = async ({ name, fn, silent = false, }) => {
if (!silent) {
logger.info(`[${name}] Started`);
}
const startTime = performance.now();
await fn();
const endTime = performance.now();
const duration = (endTime - startTime).toFixed(2);
if (!silent) {
const durationInSeconds = (Number(duration) / 1000).toFixed(3);
if (Number(duration) >= 1000) {
logger.info(`[${name}] Completed in ${durationInSeconds}s (${duration}ms)`);
}
else {
logger.info(`[${name}] Completed in ${duration}ms`);
}
}
};
//# sourceMappingURL=measure-execution-time.js.map