Improve performance monitoring by replacing console.time with performance.now for more precise timing

This commit is contained in:
2026-01-28 21:20:33 +00:00
parent 94a4d01966
commit 649c7733c3

View File

@@ -26,15 +26,16 @@ export async function perfMonitor(label, fn) {
}
const perfLabel = `${label}`;
console.time(perfLabel);
const startTime = performance.now();
try {
const result = typeof fn === 'function' ? await fn() : fn;
console.timeEnd(perfLabel);
const duration = performance.now() - startTime;
console.debug(`${perfLabel}: ${duration.toFixed(3)}ms`);
return result;
} catch (error) {
console.timeEnd(perfLabel);
console.error(`${perfLabel} failed:`, error);
const duration = performance.now() - startTime;
console.error(`${perfLabel} failed after ${duration.toFixed(3)}ms:`, error);
throw error;
}
}