()
| 200 | } |
| 201 | |
| 202 | function run() { |
| 203 | const results = {}; |
| 204 | |
| 205 | for (const scenario of SCENARIOS) { |
| 206 | if (ONLY && !scenario.name.includes(ONLY)) { |
| 207 | continue; |
| 208 | } |
| 209 | |
| 210 | // Fresh window per scenario: bounds jsdom memory growth over the |
| 211 | // run and keeps scenarios order-independent. |
| 212 | const { window } = new JSDOM('<!DOCTYPE html><body></body>'); |
| 213 | const DOMPurify = createDOMPurify(window); |
| 214 | const html = scenario.html(); |
| 215 | let sink = 0; // Defeat dead-code elimination. |
| 216 | |
| 217 | for (let i = 0; i < WARMUP; i++) { |
| 218 | sink += DOMPurify.sanitize(html, scenario.config).length; |
| 219 | } |
| 220 | |
| 221 | const times = []; |
| 222 | for (let i = 0; i < SAMPLES; i++) { |
| 223 | const t0 = performance.now(); |
| 224 | sink += DOMPurify.sanitize(html, scenario.config).length; |
| 225 | times.push(performance.now() - t0); |
| 226 | } |
| 227 | |
| 228 | results[scenario.name] = { |
| 229 | median: median(times), |
| 230 | p25: percentile(times, 25), |
| 231 | p75: percentile(times, 75), |
| 232 | min: Math.min(...times), |
| 233 | samples: SAMPLES, |
| 234 | inputBytes: html.length, |
| 235 | sink, |
| 236 | }; |
| 237 | |
| 238 | window.close(); |
| 239 | } |
| 240 | |
| 241 | return results; |
| 242 | } |
| 243 | |
| 244 | const results = run(); |
| 245 | const meta = { |
no test coverage detected