MCPcopy
hub / github.com/chenglou/pretext / run

Function run

pages/benchmark.ts:677–987  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

675}
676
677async function run() {
678 const root = document.getElementById('root')!
679 window.__BENCHMARK_REPORT__ = withRequestId({ status: 'error', message: 'Pending benchmark run' })
680 clearNavigationReport()
681 publishNavigationPhase('loading', requestId)
682
683 let topLayoutSink = 0
684 let scalingLayoutSink = 0
685 let domBatchSink = 0
686 let domInterleavedSink = 0
687
688 // Create visible DOM container
689 const container = document.createElement('div')
690 container.style.cssText = 'position:relative;overflow:hidden;height:1px'
691 document.body.appendChild(container)
692
693 const divs: HTMLDivElement[] = []
694 for (let i = 0; i < COUNT; i++) {
695 const div = document.createElement('div')
696 div.style.font = FONT
697 div.style.lineHeight = `${LINE_HEIGHT}px`
698 div.style.width = `${WIDTH_BEFORE}px`
699 div.style.position = 'relative'
700 div.style.wordWrap = 'break-word'
701 div.style.overflowWrap = 'break-word'
702 div.textContent = texts[i]!
703 container.appendChild(div)
704 divs.push(div)
705 }
706 divs[0]!.getBoundingClientRect() // force initial layout
707
708 // Pre-prepare for layout benchmark
709 const prepared: PreparedText[] = []
710 for (let i = 0; i < COUNT; i++) {
711 prepared.push(prepare(texts[i]!, FONT))
712 }
713
714 const results: BenchmarkResult[] = []
715 const richTexts = texts.slice(0, RICH_COUNT)
716 const richPreWrapTexts = Array.from(
717 { length: RICH_PRE_WRAP_COUNT },
718 (_, index) => buildPreWrapChunkStressText(index, RICH_PRE_WRAP_LINE_COUNT),
719 )
720 publishNavigationPhase('measuring', requestId)
721
722 // --- 1. prepare() ---
723 root.innerHTML = '<p>Benchmarking prepare()...</p>'
724 await nextFrame()
725 const tPrepare = bench(() => {
726 clearCache()
727 for (let i = 0; i < COUNT; i++) {
728 prepare(texts[i]!, FONT)
729 }
730 }, PREPARE_SAMPLE_REPEATS)
731 results.push({ label: 'Our library: prepare()', ms: tPrepare, desc: `One cold ${COUNT}-text measurement batch` })
732
733 // --- 2. layout() ---
734 root.innerHTML = '<p>Benchmarking layout()...</p>'

Callers 1

benchmark.tsFile · 0.70

Calls 15

clearNavigationReportFunction · 0.90
publishNavigationPhaseFunction · 0.90
prepareFunction · 0.90
clearCacheFunction · 0.90
layoutFunction · 0.90
prepareWithSegmentsFunction · 0.90
prepareRichInlineFunction · 0.90
nextFrameFunction · 0.85
benchFunction · 0.85
buildRichBenchmarksFunction · 0.85

Tested by

no test coverage detected