/* Socket Lib - Built with esbuild */
var u=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var b=(t,e)=>{for(var n in e)u(t,n,{get:e[n],enumerable:!0})},g=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of d(e))!l.call(t,o)&&o!==n&&u(t,o,{get:()=>e[o],enumerable:!(r=p(e,o))||r.enumerable});return t};var h=t=>g(u({},"__esModule",{value:!0}),t);var k={};b(k,{clearPerformanceMetrics:()=>w,generatePerformanceReport:()=>v,getPerformanceMetrics:()=>$,getPerformanceSummary:()=>f,measure:()=>x,measureSync:()=>M,perfCheckpoint:()=>T,perfTimer:()=>i,printPerformanceSummary:()=>P,trackMemory:()=>y});module.exports=h(k);var m=require("./debug");const s=[];function c(){return process.env.DEBUG?.includes("perf")||!1}function i(t,e){if(!c())return()=>{};const n=performance.now();return(0,m.debugLog)(`[perf] [START] ${t}`),r=>{const o=performance.now()-n,a={operation:t,duration:Math.round(o*100)/100,timestamp:Date.now(),metadata:{...e,...r}};s.push(a),(0,m.debugLog)(`[perf] [END] ${t} - ${a.duration}ms`)}}async function x(t,e,n){const r=i(t,n);try{const o=await e();r({success:!0});const a=s[s.length-1];return{result:o,duration:a?.duration||0}}catch(o){throw r({success:!1,error:o instanceof Error?o.message:"Unknown"}),o}}function M(t,e,n){const r=i(t,n);try{const o=e();r({success:!0});const a=s[s.length-1];return{result:o,duration:a?.duration||0}}catch(o){throw r({success:!1,error:o instanceof Error?o.message:"Unknown"}),o}}function $(){return[...s]}function w(){s.length=0,(0,m.debugLog)("[perf] Cleared performance metrics")}function f(){const t=Object.create(null);for(const n of s){const{duration:r,operation:o}=n;t[o]||(t[o]={count:0,total:0,min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY});const a=t[o];a.count++,a.total+=r,a.min=Math.min(a.min,r),a.max=Math.max(a.max,r)}const e=Object.create(null);for(const{0:n,1:r}of Object.entries(t))e[n]={count:r.count,total:Math.round(r.total*100)/100,avg:Math.round(r.total/r.count*100)/100,min:Math.round(r.min*100)/100,max:Math.round(r.max*100)/100};return e}function P(){if(!c()||s.length===0)return;const t=f(),e=Object.keys(t).sort();(0,m.debugLog)(`[perf]
=== Performance Summary ===`);for(const n of e){const r=t[n];(0,m.debugLog)(`[perf] ${n}: ${r.count} calls, avg ${r.avg}ms (min ${r.min}ms, max ${r.max}ms, total ${r.total}ms)`)}(0,m.debugLog)(`[perf] =========================
`)}function T(t,e){if(!c())return;const n={operation:`checkpoint:${t}`,duration:0,timestamp:Date.now(),...e?{metadata:e}:{}};s.push(n),(0,m.debugLog)(`[perf] [CHECKPOINT] ${t}`)}function y(t){if(!c())return 0;const e=process.memoryUsage(),n=Math.round(e.heapUsed/1024/1024*100)/100;(0,m.debugLog)(`[perf] [MEMORY] ${t}: ${n}MB heap used`);const r={operation:`checkpoint:memory:${t}`,duration:0,timestamp:Date.now(),metadata:{heapUsed:n,heapTotal:Math.round(e.heapTotal/1024/1024*100)/100,external:Math.round(e.external/1024/1024*100)/100}};return s.push(r),n}function v(){if(!c()||s.length===0)return"(no performance data collected - enable with DEBUG=perf)";const t=f(),e=Object.keys(t).sort();let n=`
\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
`;n+=`\u2551         Performance Report                    \u2551
`,n+=`\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D

`;for(const o of e){const a=t[o];n+=`${o}:
`,n+=`  Calls: ${a.count}
`,n+=`  Avg:   ${a.avg}ms
`,n+=`  Min:   ${a.min}ms
`,n+=`  Max:   ${a.max}ms
`,n+=`  Total: ${a.total}ms

`}const r=Object.values(t).reduce((o,a)=>o+a.total,0);return n+=`Total measured time: ${Math.round(r*100)/100}ms
`,n}0&&(module.exports={clearPerformanceMetrics,generatePerformanceReport,getPerformanceMetrics,getPerformanceSummary,measure,measureSync,perfCheckpoint,perfTimer,printPerformanceSummary,trackMemory});
//# sourceMappingURL=performance.js.map
