MCPcopy
hub / github.com/cure53/DOMPurify / run

Function run

scripts/benchmark.js:202–242  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

200}
201
202function 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
244const results = run();
245const meta = {

Callers 1

benchmark.jsFile · 0.70

Calls 4

createDOMPurifyFunction · 0.85
medianFunction · 0.85
percentileFunction · 0.85
sanitizeMethod · 0.80

Tested by

no test coverage detected