am-freescan/scripts/benchmark-scanner-mjpeg.mjs
lixiaolong cfff7295a6 feat(scanner): integrate scanner workflows and real-time preview
Add scanner API integration, workflow components, execution-bound live images and 3D model viewing. Harden task control, parameters, resource protection and reports, with automated regressions and detailed verification records.
2026-10-23 09:03:27 +08:00

17 lines
1.2 KiB
JavaScript

/** Fragmented-frame assembly benchmark, independent of browser rendering/FPS. */
import { consumeScannerMjpeg } from '../am-web/src/cmvr/common/utils/scannerMjpeg.mjs'
import { readFile, writeFile } from 'node:fs/promises'
const size=2*1024*1024,chunkBytes=2048
const header=new TextEncoder().encode('--frame\r\nContent-Type: image/jpeg\r\nContent-Length: '+size+'\r\n\r\n')
const bytes=new Uint8Array(header.length+size);bytes.set(header);bytes.fill(42,header.length)
let offset=0,frames=0
const stream=new ReadableStream({pull(c){if(offset>=bytes.length){c.close();return}c.enqueue(bytes.subarray(offset,offset+chunkBytes));offset+=chunkBytes}})
const started=performance.now();await consumeScannerMjpeg(stream,()=>frames++)
const after={bytes:size,chunkBytes,chunks:Math.ceil(bytes.length/chunkBytes),frames,elapsedMs:performance.now()-started}
const baselineUrl=new URL('../.local/scanner-mjpeg-baseline.json',import.meta.url)
const before=await readFile(baselineUrl,'utf-8').then(JSON.parse).catch(()=>null)
const result={environment:'Node stream assembly; not browser FPS',before,after}
await writeFile(new URL('../.local/scanner-mjpeg-performance.json',import.meta.url),JSON.stringify(result,null,2))
process.stdout.write(JSON.stringify(result,null,2)+'\n')