function isPromise(p: unknown): p is Promise { return !!p && typeof p === 'object' && 'then' in p && 'catch' in p && 'finally' in p; } export function timedLogger(label: string, fn: () => R): R { console.time(label); try { const result = fn(); if (isPromise(result)) { result.finally(() => { console.timeEnd(label); }); } return result; } catch (e) { console.timeEnd(label); throw e; } }