import assert from 'node:assert/strict' import { performance } from 'node:perf_hooks' import { extractIconHref } from '../../src/main/repo-icon-source-href.ts' // Original production expressions, preserved for the before/after measurement. const html = /]*\brel=["'](?:icon|shortcut icon)["'])(?=[^>]*\bhref=["']([^"'?]+))[^>]*>/i const object = /(?=[^}]*\brel\s*:\s*["'](?:icon|shortcut icon)["'])(?=[^}]*\bhref\s*:\s*["']([^"'?]+))[^}]*/i const original = (source) => source.match(html)?.[1] ?? source.match(object)?.[1] ?? null function measurePair(source) { original(source) extractIconHref(source) const beforeSamples = [] const afterSamples = [] for (let run = 0; run < 5; run++) { const measurements = [ [original, beforeSamples], [extractIconHref, afterSamples] ] if (run % 2 === 1) { measurements.reverse() } for (const [fn, samples] of measurements) { const started = performance.now() fn(source) samples.push(performance.now() - started) } } return { beforeMs: beforeSamples.sort((a, b) => a - b)[2], afterMs: afterSamples.sort((a, b) => a - b)[2] } } const results = [] for (const size of [8192, 16384, 32768]) { for (const variant of ['no icon', 'rel without href', 'unterminated link starts']) { const source = variant === 'unterminated link starts' ? '