import { performance } from 'node:perf_hooks' import { chromium } from 'playwright' import { imhotep } from 'imhotep' import { mkdtempSync, writeFileSync, rmSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' const tmpdir2 = mkdtempSync(join(tmpdir(), 'imhotep-full-pipeline-')) const html = `
${Array.from({length: 50}, (_, i) => `
${i}
`).join('')}
` writeFileSync(join(tmpdir2, 'page.html'), html) const browser = await chromium.launch() const page = await browser.newPage() await page.goto(`file:${join(tmpdir2, 'page.html')}`) console.log('=== Full Pipeline Benchmark ===\n') for (const count of [1, 5, 10, 25, 50]) { const ui = await imhotep(page) for (let i = 0; i < count; i++) { ui.expect(`[data-testid="item-${i}"]`).to.be.leftOf('[data-testid="item-0"]') } const times = [] for (let run = 0; run < 5; run++) { await ui.clearCache() const start = performance.now() await ui.checkAll() times.push(performance.now() - start) } const mean = times.reduce((a,b) => a+b, 0) / times.length console.log(`${count} assertions (cold): ${mean.toFixed(1)}ms (5 runs)`) } await browser.close() rmSync(tmpdir2, { recursive: true, force: true })