UNPKG

nano-performance

Version:

An extremely lightweight node module that measures execution time in nanoseconds

33 lines 827 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const perf_hooks_1 = require("perf_hooks"); const timing = {}; const timeStart = (key) => { if (!key) return null; timing[key] = perf_hooks_1.performance.now(); return true; }; const timeEnd = (key, format = 'ms') => { if (!key) return null; const start = timing[key]; if (!start) return null; let formatValue = 1000; switch (format.toLowerCase()) { case 'ns': formatValue = 1; break; } const end = perf_hooks_1.performance.now(); const result = (end - start) / formatValue; console.log(`${key}: ${result} ${format}`); delete timing[key]; return true; }; exports.default = { timeStart, timeEnd }; //# sourceMappingURL=index.js.map