Files

25 lines
1.3 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Times one render() of one line. Args: shape variant size.
// ITEM, ATX, FENCE: marker + run of size KiB + tail (u2028, u2029 or letter).
// RULE: '-' x size MiB (variant dash) or '- ' x size/2 MiB (variant dashspace).
import { readFileSync } from 'node:fs';
import { runInNewContext } from 'node:vm';
const [shape, variant, size] = process.argv.slice(2);
const src = readFileSync(process.env.MDP, 'utf8');
const window = {}; runInNewContext(src, { window });
class N { constructor(t) { this.c = []; } appendChild(x) { this.c.push(x); return x; } setAttribute() {} set textContent(v) {} get lastChild() { return this.c.at(-1); } }
const doc = { createElement: t => new N(t), createTextNode: t => ({ t }), createDocumentFragment: () => new N('#f') };
let line;
if (shape === 'RULE') {
const n = Number(size) * 1024 * 1024;
line = variant === 'dash' ? '-'.repeat(n) : '- '.repeat(n / 2);
} else {
const n = Number(size) * 1024;
const tail = { u2028: '
', u2029: '
', letter: 'x' }[variant];
line = { ITEM: '-' + ' '.repeat(n), ATX: '#' + ' '.repeat(n), FENCE: '`'.repeat(n) }[shape] + tail;
}
const meter = {};
const t0 = performance.now();
window.MosaicMarkdown.render(line, doc, meter);
const ms = performance.now() - t0;
console.log(`${shape} ${variant} ${size} len=${line.length} ms=${ms.toFixed(1)} work=${meter.work} budget=${meter.budget}`);