{"version":3,"file":"timing.cjs","names":[],"sources":["../../../src/vision/core/timing.ts"],"sourcesContent":["/** @generated Vendored from @mauriciobenjamin700/ort-vision-sdk-web. Do not hand-edit — regenerate with `npm run vendor:vision`. */\n/**\n * Per-stage timing for a single `predict()` call.\n *\n * Populates the `speed` field every `Results` envelope carries, mirroring\n * Ultralytics' `results[0].speed`. All values are milliseconds measured with\n * `performance.now()`.\n */\n\n/**\n * Stage durations of one inference, in milliseconds.\n *\n * `preprocess`, `inference` and `postprocess` are the three keys Ultralytics\n * reports, measured over the same boundaries. `load` is specific to this SDK:\n * `predict()` accepts a URL, `Blob` or DOM element and decodes it internally,\n * so the fetch/decode cost would otherwise be invisible — and on a cold cache\n * it dominates everything else.\n */\nexport interface Speed {\n    /** Fetching and decoding the input into an `RGBImage`. */\n    load: number;\n    /** Letterbox/resize, normalization and tensor packing. */\n    preprocess: number;\n    /** The ONNX Runtime forward pass. */\n    inference: number;\n    /** Decoding raw outputs into results (NMS, mask assembly, top-k). */\n    postprocess: number;\n}\n\n/**\n * Accumulate stage durations while a `predict()` call runs.\n *\n * Each `stage()` call closes the previous stage: the elapsed time since the\n * last boundary is attributed to the name given. This keeps the call sites\n * free of paired start/stop bookkeeping and guarantees the four stages tile\n * the whole call without gaps.\n */\nexport class SpeedTimer {\n    private _last: number;\n    private readonly _speed: Speed = {\n        load: 0,\n        preprocess: 0,\n        inference: 0,\n        postprocess: 0,\n    };\n\n    constructor() {\n        this._last = performance.now();\n    }\n\n    /**\n     * Attribute the time elapsed since the previous boundary to `stage`.\n     *\n     * @param stage Which stage just finished.\n     */\n    stage(stage: keyof Speed): void {\n        const now = performance.now();\n        this._speed[stage] += now - this._last;\n        this._last = now;\n    }\n\n    /**\n     * The accumulated durations.\n     *\n     * @returns The `speed` object to hand to the `Results` envelope.\n     */\n    speed(): Speed {\n        return { ...this._speed };\n    }\n}\n"],"mappings":"AAqCA,IAAa,EAAb,KAAwB,CACpB,MACA,OAAiC,CAC7B,KAAM,EACN,WAAY,EACZ,UAAW,EACX,YAAa,CACjB,EAEA,aAAc,CACV,KAAK,MAAQ,YAAY,IAAI,CACjC,CAOA,MAAM,EAA0B,CAC5B,IAAM,EAAM,YAAY,IAAI,EAC5B,KAAK,OAAO,IAAU,EAAM,KAAK,MACjC,KAAK,MAAQ,CACjB,CAOA,OAAe,CACX,MAAO,CAAE,GAAG,KAAK,MAAO,CAC5B,CACJ"}