()
| 675 | } |
| 676 | |
| 677 | async 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>' |
no test coverage detected